Solved

XML Schema Validator

Posted on 2011-02-21
3
1,285 Views
Last Modified: 2012-08-13
Hi Experts,

I've written an xml schema validator which works to a point.  I just need to try and get it a little more specific about the location of the error.  I have the schema file (.xsd) stored locally.

Is there anyway I can get the validator to give me specific line numbers in the xml file with the error?  Or at least the main element the error comes from?

txtresponse & txtxmlerror are both textboxes.

Any Help greatly appreciated.

I can provide both the schema and an xml file if required.

Thanks,
Private Sub btnvalxml_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvalxml.Click
        txtResponse.Text = "No Errors"
        Dim myDocument As New XmlDocument
        myDocument.Load("S:\Training\MOJ_Add_Claims\AYA0004-0001\AYA0004-0001.xml")
        myDocument.Schemas.Add("", "d:\XMLSchema1.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)
                txtxmlerror.Text = e.Message
                txtResponse.Text = "Errors Found"
            Case XmlSeverityType.Warning
                Debug.WriteLine("Warning {0}", e.Message)
                txtxmlerror.Text = e.Message
                txtResponse.Text = "Errors Found"
        End Select
    End Sub

Open in new window

0
Comment
Question by:jstlawyers
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Kalpesh Chhatrala earned 500 total points
ID: 34944764
0
 

Author Comment

by:jstlawyers
ID: 34953815
Hi Kalpesh,

Thanks for your post, i've download the coding,

works great,

thanks,
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 34957795
if you satisfied with answer then

Please Accept my Post as Answer and Allot Points..
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

10 Experts available now in Live!

Get 1:1 Help Now