I’m trying to make up an xml schema for the following:
<tagSet>
<Structure>
<tag>
<name>Steve</name>
</tag>
<tag>
<name>Bob</name>
</tag>
<tag>
<name>Steve</name>
</tag>
</Structure>
</tagSet>
I would like my schema to complain that Steve is there twice, but I can’t get it to work.
I have this under the tagSet element in the schema file:
<xs:key name="key" >
<xs:selector xpath="Structure/tag" />
<xs:field xpath="name" />
</xs:key>
…but I clearly haven’t understood it right, as this is not working. Anyone spot my error?
Thanks 🙂
There is nothing incorrect about your xs:key definition. Have you properly referenced the XSD in your XML file?
I copied your XML data into a document:
Then I wrote a simple XSD with your xs:key included:
And it complains about the duplicate key ‘Steve’ fine. If this example doesn’t help you find the problem, could you post more details about your schema and XML file?