views:

186

answers:

1

I've made an XSD that contains this complex Type "Text" :

<xs:complexType name="Text">
  <xs:complexContent mixed="false">
    <xs:attribute name="Id" type="xs:ID" use="required">
    </xs:attribute>
  </xs:complexContent>
</xs:complexType>

In a string, I want to find all the Text nodes that are missing the ID. Is there a way to validate the XML ?

I can't not use XPath because I have other nodes named Text that doesn't required an Id. I really need to check with the XSD.

Thank you

A: 

You can validate your xml against the xsd by specifying it on the XmlReaderSettings, and simply iterating through the XmlReader with while(reader.Read()) {}, handling the validation events (on ValidationEventHandler). For an example, see MSDN.

Note that this will report all schema errors, so if you have other problems you'll need to filter it out.

Marc Gravell