XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(null, "schema1.xsd"); // adding schema with a targetNamespace of null schemaSet.Add(null, "schema2.xsd"); schemaSet.Add("http://example.com/schema3", "schema3.xsd"); // adding a schema with a specific targetNamespace
string xml = "In this example, an XML document is loaded into an XmlDocument instance. A schema is added to an XmlSchemaSet instance, then assigned to the document's Schemas property. The document is then validated against the schema set using the Validate method. If the document is not valid according to the schemas in the set, an exception is thrown. Overall, XmlSchemaSet is a useful class for loading and managing sets of XML schemas in C#."; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(null, "schema.xsd"); doc.Schemas = schemaSet; doc.Validate(null); // validate the document against the schemas in the set text