|
-
Jun 20th, 2008, 11:03 AM
#1
Thread Starter
Lively Member
VB.NET code to validate xml against xsd file
Hi all
Does anyone have any code which shows how i can use the system.xml objects to validate an xml file against its schema file (xsd) file. Need the code in vb.net 2.0. And need something wich will give me alot of error information for example what node is incorrect and data type and length errors.
Cheers
ragioli
-
Jun 20th, 2008, 11:55 AM
#2
Re: VB.NET code to validate xml against xsd file
untested, but try this code:
Code:
Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.Xml.XPath
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myDocument As New XmlDocument
myDocument.Load("C:\somefile.xml")
myDocument.Schemas.Add("namespace here or empty string", "C:\someschema.xsd")
Dim eventHandler As ValidationEventHandler = New ValidationEventHandler(AddressOf ValidationEventHandler)
myDocument.Validate(eventHandler)
End Sub
Private Sub ValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)
Select Case e.Severity
Case XmlSeverityType.Error
Debug.WriteLine("Error: {0}", e.Message)
Case XmlSeverityType.Warning
Debug.WriteLine("Warning {0}", e.Message)
End Select
End Sub
End Class
-
Jun 23rd, 2008, 10:03 AM
#3
Thread Starter
Lively Member
Re: VB.NET code to validate xml against xsd file
Thank you very much that worked a treat :-)
-
Jan 12th, 2016, 05:48 PM
#4
New Member
Re: VB.NET code to validate xml against xsd file
Just used this, worked perfect! Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|