How to check only specific / specific tags in XML?

I have an XML code with code. I wrote an XSD to validate the XML. I have XML tags in them that do not need to be validated. Is there a way to test certain tags and skip others?

XML example:

<person>
<firstname>Name</firstname>
<lastname>Name</lastname>
<tag1>data</tag1>
<tag2>data</tag2>
<tag3>data</tag3>
</person>

I need to check only <firstname>and <lastname>and skip checking all the other elements.

+3
source share
1 answer

You cannot “ignore” elements in the sense that the parser simply skipped some XML code, but you can make your schema less restrictive by allowing any type of element as a child element.

XSD "" . :

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
      <xs:any minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

, xml, "person".

+3

Source: https://habr.com/ru/post/1727699/


All Articles