Click here to Skip to main content
15,885,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We are trying to validate xml based on schema with below code
C#
XElement xmldata = XElement.Load(@"Ad.xml");
XDocument acordRequestxml = XDocument.Parse(xmldata.ToString());
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("", @"Schema.xsd");
acordRequestxml.Validate(schemaSet, (sender, e) =>
            {

                if (sender is XObject)
                {
                    XElement dat = (XElement)sender;

                    Console.WriteLine(e.Severity);
                    switch (e.Severity)
                    {
                        case XmlSeverityType.Error:
                            Console.WriteLine(MessageFormat(e.Message) + "\n" + "XPATH        : " + GetPath(dat) + "\n");
                            break;

                        case XmlSeverityType.Warning:
                            Console.WriteLine(MessageFormat(e.Message) + "\n" + "XPATH        : " + GetPath(dat) + "\n");
                            break;
                    }
                }
            });


above code validates complete file all mandatory elements exists. but not validating if mandatory element missing or if sequence is changed.

how to validate complete xml file even mandatory missing or sequence differs?

want to get all errors in the xml at once.
Posted
Updated 23-Jul-15 21:53pm
v3
Comments
Maciej Los 24-Jul-15 4:36am    
Did you create your own schema file?
KVPalem 24-Jul-15 7:59am    
Yes

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