I'm trying to build a schema using an <xs:any />
node. When I validate it says the inserted child nodes aren't defined. I thought any
allowed me to have undefined child nodes.
My schema:
<xs:schema xmlns="Policy" targetNamespace="Policy" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Request">
<xs:complexType>
<xs:sequence>
<xs:any />
</xs:sequence>
<xs:attribute name="Routing" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
My XML:
<gp:Request Routing="foo" xmlns:gp="Policy">
<bar/>
</gp:Request>
It flags the bar
node. What am I doing wrong?
CodePudding user response:
You're witnessing the expected behavior for xs:any/@processContents="strict"
, which is the default value. When @processContents
is set to strict
, the element definition must exist, and the element in the XML must be valid against that declaration.
Change to
<xs:any processContents="lax" />
if you want validation to occur only if the element definition exists, or
<xs:any processContents="skip" />
if you want no validation to take place regardless of whether the element is defined in the XSD.