XSD for XML with all unique node names
My XML file looks something like this:
<Fields>
<Humanities>
<Performing_Arts>
<Dance />
<Music />
</Performing_Arts>
<Visual_Arts>
<Painting />
<Sculptue />
</Visual_Arts>
</Humanities>
<Social_Sciences>
<Psychology>
<Cultural_Psychology />
<Social_Psychology 开发者_Python百科/>
</Psychology>
</Social_Sciences>
</Fields>
I want to write an XML Schema, for this file, so that no two nodes, irrespective of location in the file can have duplicate names. Any node in this file should be allowed to have unlimited child nodes, to any sub-level.
How might I achieve this goal?
skaffman is quite right, you needto enclose your values as either attributes or elements, if you are unsure, w3 schools hasa great tutorial on this;
http://www.w3schools.com/xml/xml_elements.asp http://www.w3schools.com/xml/xml_attributes.asp
An example of a possible xml representation of your data might be:
<fields>
<department name="Humanities">
<subject name="Peforming Arts">
<topic name="Dance"/>
<topic name="Music"/>
</subject>
<subject name="Visual Arts">
<topic name="Painting"/>
<topic name="Sculpture"/>
</subject>
</department>
<department name="Social Sciences">
<subject name="Psychology">
<topic name="Cultural Psychology"/>
<topic name="Social Psychology"/>
</subject>
</department>
</fields>
Notes:
You can see that this is roughly equivalent to a database with three tables: department, subject and topic, with FK relationships between the parent and children. This is really what XML encapsulates, but in text form, and is the sort of thing to bear in mind while you design your layout.
I've used all lower-case names for elements and attributes. This is a personal thing as xsl/xpath as case sensitive, so making everything lowercase avoids the opporyunity for horrid bugs later
精彩评论