XSD: key and keyref problem

boeledi

Usenet Archive
Joined
Nov 15, 2005
Messages
7
Reaction score
0
Hello,

Here is a sample of XML I would like to obtain.

<message xmlns = "........">
<Entities>
<Persons>
<Person entityID="12">
<Name>Name1</Name>
<Info>blablabla</Info>
</Person>

<Person entityID="34">
<Name>Another person</Name>
<Info>Another information</Info>
</Person>
</Persons>

<Companies>
<Company entityID="145">
<Name>My First Company</Name>
<Address>AddressOfFirstCompany</Address>
</Company>

<Company entityID="235">
<Name>My Second Company</Name>
<Address>AddressOf SecondCompany</Address>
</Company>
</Companies>
</Entities>

<!-- Details part -->

<Details>
<Info1>jqdjqdkjqdqjdlqjdqlk</Info1>
<Owner refEntityId = "145" />
<Driver refEntityId = "12" />
<Contact refEntityId = "34" />
</Details>
</message>

....a little bit of information:
1. Persons and Companies are both extensions of a same ComplexType:
Entity (here is an extract of the definitions)

<!-- Entity -->
<xs:complexType name="entity">
<xs:sequence>
<xs:element name="type" type="xs:string" />
<xs:element name="name" type="xs:string" />
...
</xs:sequence>
<xs:attribute name="entityID" type="xs:integer" />
</xs:complexType>

<!-- Person -->
<xs:complexType name="person">
<xs:complexContent>
<xs:extension base="myns:entity">
<xs:sequence>
<xs:element name="firstNames" type="xs:string" />
<xs:element name="sex" type="xs:integer" />
<xs:element name="placeOfBirth" type="xs:string" /> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType>

<!-- Company -->
<xs:complexType name="company">
<xs:complexContent>
<xs:extension base="myns:entity">
<xs:sequence>
<xs:element name="tradingNames" type="xs:string" /> <xs:element name="remarks" type="xs:string" /> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType>
2. I would like to be able to either refer to a Person or a Company when I am specifying the "owner", "driver" or "contact"

A first thought was...

<xs:complexType name="messageContent">
<xs:sequence>
<xs:element name="Entities" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="Persons" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="person" type="myns:person" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Companies" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="company" type="myns:company" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element>

<xs:element name="Details" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="Info1" type="xs:string" /> <xs:element name="Owner" type="myns:refToEntity" minOccurs="1" maxOccurs="1" /> <xs:element name="Driver" type="myns:refToEntity" minOccurs="1" maxOccurs="1" /> <xs:element name="Contact" type="myns:refToEntity" minOccurs="1" maxOccurs="1" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType>

<xs:complexType name="refToEntity">
<xs:complexType>
<xs:attibute name="refEntityId" type="xs:integer" />
</xs:complexType>
</xs:complexType>

<xs:element name="message" type="myns:messageContent" />

....but I don't know how (or where) to put 'ref' and/or 'keyref' in order to answer my needs?

Could anyone help me?

Thanks in advance,

Didier
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
boeledi said:
<xs:element name="message" type="myns:messageContent" />

Make the xs:key and xs:keyref elements children of the above xs:element name="message" element. Also pay attention to namespaces when you write the XPath expressions for the selectors.
 

boeledi

Usenet Archive
Joined
Nov 15, 2005
Messages
7
Reaction score
0
Make the xs:key and xs:keyref elements children of the above xs:element name="message" element. Also pay attention to namespaces when you write the XPath expressions for the selectors.

Thank you for the answer but I am still confused...

Since I want the elements "Owner, Driver and Contact" to reference either a person or a company, I have got a problem with the definition of the xpath of the "xs:selector". How can I say that the xpath is either refering to ".//Entities/Persons/person" or "../Entities/ Companies/company" ?? The only solution I found (up to now) was to use "entity", rather than "person" or "company"

<xs:element name="Entities" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="Persons" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="entity" type="myns:person" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Companies" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="entity" type="myns:company" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element>

and ... then to set ...
<xs:selector xpath=".//Entities/*/entity" />
<xs:field xpath="@entityID"

but isn't there anything better?
 

Arndt Jonasson

Usenet Archive
Joined
Oct 11, 2004
Messages
255
Reaction score
0
Since I want the elements "Owner, Driver and Contact" to reference either a person or a company, I have got a problem with the definition of the xpath of the "xs:selector". How can I say that the xpath is either refering to ".//Entities/Persons/person" or "../Entities/ Companies/company" ??

If I'm not misunderstanding the question, you can use the | separator in XPath - it does a set union operation, so (//a | //b) refers to all elements named either a or b, for example.
 
Joined
Sep 6, 2012
Messages
1
Reaction score
0
xsd:keyref validation message

Hello All,

I'm using xs:key and xs:keyref validation. When I enter invalid value foreign key constraint (keyref) error message is shown on the root node but not on the node where I entered invalid value. Is there a way so that I can see this error message on node where I entered invalid value? Please let me know.

Thanks in advance.

Regards,
Kishan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,244
Members
248,133
Latest member
DujonT

Latest Threads

Top