I’m trying to create an xml-schema (xsd) to validate an xmlfile.
<a>
<b>
<c>...</c>
<d>...</d>
</b>
<b>
<c>...</c>
<e>...</e>
<d>...</d>
</b>
<a>
1 a-element.
Multiple b-elements, that have some content.
I want to validate that a is present in the file, and 1 or more occurances of b. I’m not interested to know what is inside of b.
So this is what I tried:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element name="b" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="b">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I hoped that the any-element would do the magic trick, but it does not. What am I doing wrong?
edit:
XmlSpy gives me this error: Element ‘c’ not defined in DTD/Schema.
You don’t need the additional ‘b’ in the schema, I think what you’re looking for is this:
This states that you have
<a>as a root node, and it can contain one or more<b>sEdit: Sorry, didn’t read the full question – try the above!
Second edit: Another attempt above!