We help IT Professionals succeed at work.
Get Started

Validate XML

jdhackett
jdhackett asked
on
488 Views
Last Modified: 2012-05-09
Hi
I have some code which validates XML. It write all the errors to a text box. I've attached the code.

All works fine. However, it would be better if it gave more details. For example, which line of the XML is the issue. Anyone got an idea how to do this?

Thanks

Public Class frmValidate

   Public Target_XML As String

   Private Sub btnValidate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidate.Click

      Try

         Dim Validator As New XmlValidator()
         Dim Errors As List(Of String)
         Dim RawXml As String

         Const MY_XSD As String = "C:\Sample\Tras_V7_09.xsd"

         Using Reader As New StreamReader(Target_XML)
            RawXml = Reader.ReadToEnd()
         End Using

         With Validator
            .SchemaSettings.ProhibitDtd = False
            .Schemas.Add(MY_XSD)

            Errors = .ValidateXml(RawXml)
         End With

         Me.txtErrors.Text = "Errors:" & Errors.Count & vbCrLf & vbCrLf
         For Each Err As String In Errors
            Me.txtErrors.Text &= Err & vbCrLf
         Next

         MsgBox("Complete")

      Catch ex As Exception
         msgError(ex.Message, "XML Validate")
      End Try

   End Sub
   
End Class

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE