Solved

Help with checking xml format against its .xsd file

Posted on 2014-04-29
3
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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