Solved

XML Schema Validator

Posted on 2011-02-21
3
1,289 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

18 Experts available now in Live!

Get 1:1 Help Now