How can I define an XSD file that allows unknown (wildcard) elements?

前端 未结 2 1935
不知归路
不知归路 2020-12-06 01:50

I\'m receiving an XML message with unknown variable name elements... that is, they are not predefined...

I only know there can be 0 or more of those elements, along

相关标签:
2条回答
  • 2020-12-06 02:14

    What you want is a wildcard particle, for details see http://www.w3.org/TR/xmlschema-1/#Wildcards

    To do it you can use xs:any. Note that xs:element and xs:any cannot be placed directly inside an xs:complexType. You need a container like a sequence or choice.

    A valid schema that handles wildcards is below:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
      <xs:element name="root">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="service" type="xs:string"/>
            <xs:element name="resource" type="xs:string"/>
            <xs:element name="action" type="xs:string"/>
            <xs:element name="parameters">
              <xs:complexType>
                <xs:sequence maxOccurs="unbounded">
                  <xs:any processContents="lax"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    
    </xs:schema>
    
    0 讨论(0)
  • 2020-12-06 02:14

    Try this:

    <xs:element name="parameters">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded">
              <xs:complexType>
                <xs:sequence>
                  <xs:any processContents="lax"></xs:any>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    
    0 讨论(0)
提交回复
热议问题