Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with checking xml format against its .xsd file

Posted on 2014-04-29
3
Medium Priority
?
221 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 2000 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 64

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

721 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