<any> doesn't work in XSD?
I am trying to create an xml schema (xsd) to validate an xml file.
<a>
<b>
<c>...</c>
<d>...</d>
</b>
<b>
<c>...</c>
<e>...</e>
<d>...</d>
</b>
<a>
1 a-element. Several b elements that have some content.
I want to check that a is present in the file, and 1 or more cases of b. I am not interested in knowing what is inside b.
So here 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 was hoping that any element would do the magic trick, but it is not. What am I doing wrong?
edit XmlSpy gives me this error: The 'c' element is not defined in DTD / Schema.
+3
2 answers
You do not need extra “b” in the schema, I think what you are looking for:
<?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:complexType>
<xs:sequence>
<xs:any maxOccurs="unbounded" minOccurs="1" processContents="lax"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
, <a> node, <b> s
: , - !
: !
+2