To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Jun 20th, 2008, 11:03 AM   #1
ragstta
Lively Member
 
Join Date: Jan 07
Location: England
Posts: 64
ragstta is an unknown quantity at this point (<10)
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
ragstta is offline   Reply With Quote
Old Jun 20th, 2008, 11:55 AM   #2
kleinma
Moderator.NET
 
kleinma's Avatar
 
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 22,482
kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)
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! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

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=-
kleinma is offline   Reply With Quote
Old Jun 23rd, 2008, 10:03 AM   #3
ragstta
Lively Member
 
Join Date: Jan 07
Location: England
Posts: 64
ragstta is an unknown quantity at this point (<10)
Re: VB.NET code to validate xml against xsd file

Thank you very much that worked a treat :-)
ragstta is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:01 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.