I am new to xsd validation, and am trying to validate if a choice tag has a specific group of elements but also has ones with arbitrarily named. Something like the following:
...
<xs:choice>
<xs:element name="test1" type="xs:string" />
<xs:element name="test2" type="xs:string" />
<xs:element name="-some regex or something to specify arbitrary name here" type="xs:string" />
</xs:choice>
...
Xml:
...
<test1>example text</test1>
<test2>example text again</test2>
<exampleNode>example text</exampleNode>
...
Is this possible in xsd? To validate against new arbitrarily named nodes?
You can use the xs:any wildcard to allow any element name, or any name within a particular set of namespaces. You can't restrict the name further (except by using assertions in XSD 1.1).
Using names with an internal structure (e.g. address-line-1, address-line-2, address-line-3) is invariably bad practice in XML design. In this case, a better design is <address-line nr="1"> etc. So the idea of allowing names that match some regular expression suggests poor design. In general, XML Schema has been designed to make it difficult or impossible to write a schema for a poorly designed vocabulary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With