Results 1 to 3 of 3

Thread: Using MSXML5 to Validate XML to Schema

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    2

    Using MSXML5 to Validate XML to Schema

    I am using the following vb6 function to validate my xml against its schema file:


    Function ValidateAsXmlFile(strFileName As String) As Boolean

    Dim xmlDoc As MSXML2.DOMDocument50

    Set xmlDoc = New MSXML2.DOMDocument50

    xmlDoc.validateOnParse = True
    xmlDoc.async = False
    xmlDoc.Load (strFileName)

    Select Case xmlDoc.parseError.errorCode
    Case 0 ' Passed Validation
    ValidateAsXmlFile = True
    Case Else ' Failed Validation
    ValidateAsXmlFile = False
    MsgBox vbCrLf & "ERROR! Failed to validate " & _
    strFileName & vbCrLf & xmlDoc.parseError.reason & vbCrLf & _
    "Error code: " & xmlDoc.parseError.errorCode & vbCrLf & "Line: " & _
    xmlDoc.parseError.Line & vbCrLf & "Character: " & _
    xmlDoc.parseError.linepos & "", vbExclamation, "XML Failed to Validate Against Schema"
    End Select

    Set xmlDoc = Nothing

    End Function


    This works fine except that it only identifies the 1st error. You can't tell if there are follow-on errors. Once you correct this error and re-validate then you may find a 2nd error and so on. I would like to be able to see all errors at once. Any ideas?


    Tim

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Using MSXML5 to Validate XML to Schema

    Welcome to the forums.

    Does the entire process stop when it encounters and error?

    How do you call this Function?

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    2

    Re: Using MSXML5 to Validate XML to Schema

    It seems that it just finds any error and stops searching. My guess is it's designed like this in the MSXML. The method seems looks for any error and reports it and that's it. It doesn't seem to compile all the errors in a list. The xmlDoc.parseError.errorCode method within the MSXML5.DLL seems to exit after any one error found. There doesn't appear to be a way to set a starting or ending point to search for an error.

    I call my VB function like this:

    XMLValidated = ValidateAsXmlFile("C:\myXMLfile.xml")


    Tim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width