Solved

Help with checking xml format against its .xsd file

Posted on 2014-04-29
3
209 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 62

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now