|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IsXmlValid functionI would like to validate an XML document in a VB.NET app.
This is the function that I'm after: Public Shared Function IsXmlValid(ByVal xmlPath As String, ByVal xsdPath As String) as Boolean 'code here End Sub Can someone help me with the code ? Thanks, Craig You'll need more than just XML file path and XSD file path, you'll also need
the namespace name as one XML file can use multiple schemas. Here's an example from MSDN of validating an XML file to a single schema: void DoSomething() { // Create the XmlSchemaSet class. XmlSchemaSet sc = new XmlSchemaSet(); // Add the schema to the collection. sc.Add("urn:bookstore-schema", "books.xsd"); // Set the validation settings. XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas = sc; settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack); // Create the XmlReader object. XmlReader reader = XmlReader.Create("booksSchemaFail.xml", settings); // Parse the file. while (reader.Read()); } // Display any validation errors. private static void ValidationCallBack(object sender, ValidationEventArgs e) { Console.WriteLine("Validation Error: {0}", e.Message); } -- Show quoteBrowse http://connect.microsoft.com/VisualStudio/feedback/ and vote. http://www.peterRitchie.com/blog/ Microsoft MVP, Visual Developer - Visual C# "Craig HB" wrote: > I would like to validate an XML document in a VB.NET app. > > This is the function that I'm after: > > Public Shared Function IsXmlValid(ByVal xmlPath As String, ByVal xsdPath As > String) as Boolean > 'code here > End Sub > > Can someone help me with the code ? > > Thanks, > Craig |
|||||||||||||||||||||||