R Rahul Aggarwal Jun 8, 2004 #1 Hi, How can you validate an xml document against a schema in c#. Thanks Rahul
C christian strevel Jun 8, 2004 #2 Of course, it goes somehting like this: String xmlFrag = "<author xmlns='urn:bookstore-schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" + "<first-name>Herman</first-name>" + "<last-name>Melville</last-name>" + "</author>"; XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context); myschema.Add("urn:bookstore-schema", "c:\\Books.xsd"); reader.ValidationType = ValidationType.Schema; reader.Schemas.Add(myschema); while (reader.Read()) { }
Of course, it goes somehting like this: String xmlFrag = "<author xmlns='urn:bookstore-schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" + "<first-name>Herman</first-name>" + "<last-name>Melville</last-name>" + "</author>"; XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context); myschema.Add("urn:bookstore-schema", "c:\\Books.xsd"); reader.ValidationType = ValidationType.Schema; reader.Schemas.Add(myschema); while (reader.Read()) { }