1
votes

Trying to validate XML schema where the XML contains ids in the elements.

XML:

<A:System id="systemName">
            <A:SystemCd>001</A:SystemCd>
</A:SourceSystem>

XSD:

<xs:element name="System" maxOccurs="unbounded">
      <xs:complexType>
            <xs:sequence>
                  <xs:element name="SystemCd" />
            </xs:sequence>
      </xs:complexType>
</xs:element>

Error:

Exception: cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'System'.

Is there a way to continue to validate child elements when parent elements contain IDs?

1

1 Answers

2
votes

Add an id attribute to the System element in the XSD:

<xs:element name="System" maxOccurs="unbounded">
      <xs:complexType>
            <xs:sequence>
                  <xs:element name="SystemCd" />
            </xs:sequence>
            <xs:attribute name="id" type="xs:ID"/>
      </xs:complexType>
</xs:element>