I try to define a schema for XML documents I receive.
The documents look like:
<root> <items> <group name='G-1'> <item name='I-1'/> <item name='I-2'/> <item name='I-3'/> <item name='I-4'/> </group> </items> <data> <group name='G-1' place='here'> <customer name='C-1'> <item name='I-1' count='3'/> <item name='I-2' count='4'/> </customer> <customer name='C-2'> <item name='I-3' count='7'/> </customer> </group> </data> </root>
I tried XmlSpy and xsd.exe from .NET 2.0. Both created schema definitions which allow below <group> any number of <item> and <customer> elements. But what I’m looking for should restrict <group> below <items> to <item> elements, and <group> below <data> to <customer> elements.
Is this something xml schema is not capable at all?
Yes, XSD can handle this. I generated this schema from Visual Studio 2008 (much faster than doing it by hand) and it will do what you’re looking for: