tags:

views:

20

answers:

1

I have some code-generated XML. I have written an XSD to validate the XML. I have tags in them XML that do not need to be validated. Is there any way to validate particular tags and skip the others?

The example XML is:

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

I need to validate only <firstname> and <lastname> and to skip the validation of all other elements.

+3  A: 

You can't "ignore" elements in terms of having the parser just skip through some of the XML, but you can make your schema less strict by allowing any type of element as a child element.

XSD allows this by the use of the "any" element. Example:

<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>

Now you can have any unknown but valid xml element show up as a child of a "person" element.

womp