How do I specify a child element in an XML schema with a name but any content?

I am trying to write XML schema code to indicate that a particular "abc" element can have a child element named "xyz" and that element can have any attributes and any child elements.

At the moment I have this:

    <xs:element name="abc">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="xyz">
            <xs:complexType>
              <xs:sequence>
                <xs:any/>
              </xs:sequence>
              <xs:anyAttribute/>               
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>

      

But when I validate my XML against the schema, I get validation errors, complaining about the children of the xyz element.

+2


a source to share


1 answer


Your xs: each doesn't have any information associated with it, so it looks for schema-defined items. If you want to be weak in your interpretation of subelements, try this:

<xs:element name="abc">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="xyz">
        <xs:complexType>
          <xs:sequence>
            <xs:any processContents="lax" />
          </xs:sequence>
          <xs:anyAttribute/>               
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

      



This should be verified. If you have an expectation of the correctness of the xyz content, you can include the namespace using the namespace attribute for xs: any and pull out another schema for that information.

Good luck and I hope this helps!

+1


a source







All Articles