Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to show multiple invalid child elements on comparing an input xml with a standard schema in asp.net with c#?


I am validating the xml with the schema mentioned below:
XSD schema:
XML
<?xml version="1.0" encoding="Windows-1252"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"     xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Stats">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="Name">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="FirstName" type="xs:string" maxOccurs="1" />
              <xs:element name="LastName" type="xs:string" maxOccurs="1" />
              <xs:element name="Address" type="xs:string" maxOccurs="1" />
             </xs:sequence>
          </xs:complexType>
        </xs:element>

      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>


Xml file:
XML
<Stats>

  <Name>
    <FirstName>fdsfdsf</FirstName>
    <LastName>jkhkh</LastName>
    <Address>jkhkhdsfd</Address>
    <Age>25</Age>
    <Department>25</Department>
    </Name>
  </Stats>



But I am getting the validation errors mentioned below only one by one. I want to get both the errors together.

FileName: input.xml Validation Error: The element 'Name' has invalid child element 'Age'.
FileName: input.xml Validation Error: The element 'Name' has invalid child element 'Department'.
Posted

1 solution

Check this: XmlDocument.Validate Method (ValidationEventHandler)[^]. On the bottom of page you'll find an example which illustrates how to use Validate method to display all errors/warnings.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900