Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSD: key and keyref problem

Reply
Thread Tools

XSD: key and keyref problem

 
 
boeledi
Guest
Posts: n/a
 
      10-15-2007
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="mynserson" 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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-15-2007
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/
 
Reply With Quote
 
 
 
 
boeledi
Guest
Posts: n/a
 
      10-15-2007
On 15 oct, 15:04, Martin Honnen <(E-Mail Removed)> 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="mynserson"
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?


 
Reply With Quote
 
Arndt Jonasson
Guest
Posts: n/a
 
      10-17-2007
On Oct 15, 3:15 pm, boeledi <(E-Mail Removed)> 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.

 
Reply With Quote
 
Kris824 Kris824 is offline
Junior Member
Join Date: Sep 2012
Posts: 1
 
      09-06-2012
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problems with key/keyref and complex-type inheritance peterpeter XML 0 02-12-2007 08:17 PM
key and keyref Mike XML 3 09-27-2005 09:35 AM
Xml Schema substitution groups / key and keyref John Carron XML 0 09-01-2005 06:52 PM
XML schema - key/keyref and inheritance peterpeter XML 0 02-11-2004 01:38 PM
Can't use key and keyref with an attribute in a group J E E XML 0 11-07-2003 12:42 PM



Advertisments