How to specify "any item" in a sequence

Can anyone tell me how to indicate in the 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 an XSD element to describe the element <person>

, what will come after " <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>

      

+3


source to share


2 answers


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 special attention to the possible values processContent

:

  • skip : Allow any element and ignore any definition for an element.
  • lax : Allow any element, but check the element if any definition is found for it.
  • strict : Allow any element, but require it to have a definition and be valid for that definition.
+4


source


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) fails with xs:any

but is xs:anyAttribute

supported

0


source







All Articles