Click here to Skip to main content
15,898,987 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

Iam getting an xml string and iam converting into xmlelemet using the following code

C#
private static XmlElement GetElement(string xml)
{
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xml);
    return doc.DocumentElement;
}


now i want to check whehter this xml is a valid one or not using xsd but how can but i have the following code

C#
XmlReader xsd = new XmlTextReader(XsdPath);
                XmlSchemaSet schema = new XmlSchemaSet();
                schema.Add(null, xsd);

                XmlReaderSettings xmlReadeSettings = new XmlReaderSettings();
                xmlReadeSettings.ValidationType = ValidationType.Schema;
                xmlReadeSettings.Schemas.Add(schema);
                xmlReadeSettings.ValidationEventHandler += new ValidationEventHandler(ValidationHandler);

                XmlTextReader xmlTextReader = new XmlTextReader(xmlPath);
                XmlReader xmlReader = XmlReader.Create(xmlTextReader, xmlReadeSettings);

which reads an xml from a file ....instead

how can check xmlelement instead of the xml path to validate


thanks in advance
Posted
Updated 21-May-12 21:45pm
v2
Comments
Anuja Pawar Indore 22-May-12 3:45am    
Added pre tag

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