Solved

Help with checking xml format against its .xsd file

Posted on 2014-04-29
3
214 Views
Last Modified: 2014-05-03
Hi,

How do you verify the xml file adheres to its schema using VB.NET?

Thanks,

Victor
0
Comment
Question by:vcharles
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 40031582
You would do something like:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim settings As New XmlReaderSettings
        settings.ValidationType = ValidationType.Schema

        settings.Schemas.Add(XmlSchema.Read(New XmlTextReader("C:\temp\shiporder.xsd"), AddressOf ValidationHandler))

        Dim reader As XmlReader = XmlReader.Create("C:\temp\shiporder.xml", settings)

        Dim doc As New XmlDocument()
        doc.Load(reader)

    End Sub

    Private Sub ValidationHandler(sender As Object, e As ValidationEventArgs)
        MessageBox.Show(e.Message)
    End Sub

Open in new window

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40032010
Hi Victor;

You can also use Linq to check a XML document against a XSD file. See Microsoft documentation which also has an example at the bottom of the page. If you have any questions please ask.

XDocument.Validate Method
0
 

Author Closing Comment

by:vcharles
ID: 40039519
Thank You.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question