|
|
#1 |
|
Lively Member
Join Date: Jan 07
Location: England
Posts: 64
![]() |
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
|
|
|
|
|
|
#2 |
|
Moderator.NET
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 22,482
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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
__________________
Using VB.NET 2010/.NET 2.0 through 4.0 * Please mark you thread resolved using the Thread Tools above ![]() PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!! * If you found a post useful then please Rate it! Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup ZerosAndTheOne.com -=Matt=- |
|
|
|
|
|
#3 |
|
Lively Member
Join Date: Jan 07
Location: England
Posts: 64
![]() |
Re: VB.NET code to validate xml against xsd file
Thank you very much that worked a treat :-)
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|