unique integer id as attribute

M

Mario

Hi,

I want to use a unique ID attribute, which should be an integer value.
I tried the solution below with xpath, but the xml seems to be valid,
even if there are two equal ids. Any idea why?


My XSD
---------------------------------------------------------------------
<xs:element name="sample">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="one" maxOccurs="10">
<xs:complexType>
<xs:attribute name="anothertxt" type="xs:string"/>
<xs:attribute name="sequenceid" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="two" maxOccurs="10">
<xs:complexType>
<xs:attribute name="sequenceid" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="three" maxOccurs="10">
<xs:complexType>
<xs:attribute name="sequenceid" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="seqid">
<xs:selector xpath=".//sample"/>
<xs:field xpath="@sequenceid"/>
</xs:key>
</xs:element>
---------------------------------------------------------------------

My XML
---------------------------------------------------------------------
<sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sample.xsd">
<one sequenceid="1"/>
<one sequenceid="2"/>
<two sequenceid="3"/>
<two sequenceid="3"/>
</sample>
---------------------------------------------------------------------
 
M

Martin Honnen

Mario wrote:

I want to use a unique ID attribute, which should be an integer value.
I tried the solution below with xpath, but the xml seems to be valid,
even if there are two equal ids. Any idea why?


My XSD
<xs:key name="seqid">
<xs:selector xpath=".//sample"/>

Why the path to sample if the sequenceid attribute is on the other
elements, e.g. one or two?
 
M

Mario

I thought this might be the only possibility to get the sequence ID
unique for all element-attributes below <sample>... is this wrong?
 
M

Martin Honnen

Mario said:
I thought this might be the only possibility to get the sequence ID
unique for all element-attributes below <sample>... is this wrong?

You should be able to use
<xs:selector xpath=".//*">
to match any descendant element, at least that is my current reading of
the XML schema specification. Try that.
It should also be possible to list alternatives e.g.
<xs:selector xpath="one | two | three">
 

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
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top