X
X. Lee
Hi, please take a look at this schema and tell me how I can make the
value of my AttachmentKey element(s) unique within the entire instance
document.
I know that I have to use <key> or <unique>, but I can't get it to
work. I don't have knowledge of xpath and the examples I find on the
web aren't working.
here is my schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="test.ns.abc">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:A"/>
<xsd:element ref="ns:Attachment" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Attachment">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:AttachmentKey"/>
<xsd:element ref="ns:AttachmentName"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AttachmentText" type="xsd:string"/>
<xsd:element name="AttachmentName" type="xsd:string"/>
<xsd:element name="AttachmentPageTotal" type="xsd:int"/>
<xsd:element name="A">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:B"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="B">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:Attachment"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AttachmentKey"/>
</xsd:schema>
--------------
As you can see, AttachmentKey is a subelement of Attachment, and is
used in more than one place in the example above. I want it so that
when the instance document is created, no matter how many instances of
Attachment is in it, each AttachmentKey value is unique, so that I can
use them as keys.
So this following instance doc would be invalid:
<root>
<A>
<B>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</B>
</A>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
<Attachment>
<AttachmentKey>2</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</root>
But this one would be valid:
<root>
<A>
<B>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</B>
</A>
<Attachment>
<AttachmentKey>2</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
<Attachment>
<AttachmentKey>3</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</root>
thanks!
value of my AttachmentKey element(s) unique within the entire instance
document.
I know that I have to use <key> or <unique>, but I can't get it to
work. I don't have knowledge of xpath and the examples I find on the
web aren't working.
here is my schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="test.ns.abc">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:A"/>
<xsd:element ref="ns:Attachment" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Attachment">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:AttachmentKey"/>
<xsd:element ref="ns:AttachmentName"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AttachmentText" type="xsd:string"/>
<xsd:element name="AttachmentName" type="xsd:string"/>
<xsd:element name="AttachmentPageTotal" type="xsd:int"/>
<xsd:element name="A">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:B"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="B">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:Attachment"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AttachmentKey"/>
</xsd:schema>
--------------
As you can see, AttachmentKey is a subelement of Attachment, and is
used in more than one place in the example above. I want it so that
when the instance document is created, no matter how many instances of
Attachment is in it, each AttachmentKey value is unique, so that I can
use them as keys.
So this following instance doc would be invalid:
<root>
<A>
<B>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</B>
</A>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
<Attachment>
<AttachmentKey>2</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</root>
But this one would be valid:
<root>
<A>
<B>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</B>
</A>
<Attachment>
<AttachmentKey>2</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
<Attachment>
<AttachmentKey>3</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</root>
thanks!