![]() |
XSD: key and keyref problem
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 |
Re: XSD: key and keyref problem
boeledi wrote:
> <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? 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. -- Martin Honnen http://JavaScript.FAQTs.com/ |
Re: XSD: key and keyref problem
On 15 oct, 15:04, Martin Honnen <mahotr...@yahoo.de> wrote:
> boeledi wrote: > > <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? > > 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. > > -- > > Martin Honnen > http://JavaScript.FAQTs.com/ 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? |
Re: XSD: key and keyref problem
On Oct 15, 3:15 pm, boeledi <didier.boel...@steams.be> wrote:
> 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. |
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. |
| All times are GMT. The time now is 07:49 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.