Reputation: 1445
Could someone tell me how to specify in an XSD, that an element can contain any number of arbitrary elements? For exmaple, if I have
<person>
<name>Foo</name>
</person>
I would like to allow any element after the "<name>
" element.
<person>
<name>Foo</name>
<gender>male</gender>
</person>
<person>
<name>Foo</name>
<address>west of here</address>
</person>
<person>
<name>Foo</name>
<address>west of here</address>
<spooge>something else</spooge>
</person>
That is, the name element is required, but after that, you can add any arbitrary element with any type. So if this is the XSD element to describe the <person>
element, what would go after the "<xs:element name='name' .../>
"
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Upvotes: 3
Views: 5560
Reputation: 2787
The solution for me was :
<xs:complexType name="dataType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:anyAttribute processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
My IDE (PHPStorm) run error with
xs:any
butxs:anyAttribute
is supported
Upvotes: -2
Reputation: 111786
You can use xsd:any
:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:any processContents="skip" namespace="##any"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Pay particular attention to the possible values for processContent
:
Upvotes: 6