Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:02
Show Gist options
  • Save adojos/ddcd8fb90b737827f2ce4058f4a5655f to your computer and use it in GitHub Desktop.
Save adojos/ddcd8fb90b737827f2ce4058f4a5655f to your computer and use it in GitHub Desktop.
VBS: Parse XSD Validation Errors #vbs
' The .AllErrors contains errors and warnings found DURING validation. Not valid for Load errors.
' Applies to IXMLDOMParseError2 interface which extends the IXMLDOMParseError interface
Public Function ParseValidationError (ByVal ObjParseErr, ObjXMLDoc)
Dim strResult, ErrFound
ErrFound = 0
Select Case ObjParseErr.errorCode
Case 0
ConsoleOutput "", "verbose", LogHandle
strResult = "<INFO> XML SCHEMA VALIDATION: SUCCESS ! " & vbCrLf & ObjXMLDoc.url & vbCrLf '& ObjXSDDoc.url
ConsoleOutput strResult, "verbose", LogHandle
ParseError = True
Case Else
If (ObjParseErr.AllErrors.length > 1) Then '.AllErrors contains errors and warnings found DURING validation. Not valid property for Load errors
ConsoleOutput "<ERROR> VALIDATION FAILED WITH MULTIPLE ERRORS !" & vbCrLf, "verbose", LogHandle
For Each ErrorItem In ObjParseErr.AllErrors
strResult = "[" & ErrFound+1 & "]" & " ERROR REASON :" & _
vbCrLf & " ------------" & vbCrLf & ErrorItem.reason & vbCrLf & _
"Error Code: " & ErrorItem.errorCode & ", Line: " & _
ErrorItem.Line & ", Character: " & _
ErrorItem.linepos & ", Source: " & _
Chr(34) & ErrorItem.srcText & vbCrLf & vbCrLf & _
"XPath Value : " & vbCrLf & ErrorItem.errorXPath & vbCrLf
'ConsoleOutput ObjXMLDoc.url
ConsoleOutput strResult, "verbose", LogHandle
ErrFound = ErrFound + 1
Next
Else
ConsoleOutput "<ERROR> VALIDATION FAILED WITH A SINGLE ERROR !" & vbCrLf, "verbose", LogHandle
strResult = " ERROR REASON :" & _
vbCrLf & " ------------" & vbCrLf & ObjParseErr.reason & vbCrLf & _
"Error Code: " & ObjParseErr.errorCode & ", Line: " & _
ObjParseErr.Line & ", Character: " & _
ObjParseErr.linepos & ", Source: " & _
Chr(34) & ObjParseErr.srcText & vbCrLf & vbCrLf & _
"XPath Value : " & vbCrLf & ObjParseErr.errorXPath & vbCrLf
ConsoleOutput strResult, "verbose", LogHandle
ErrFound = ErrFound + 1
End If
End Select
If ErrFound > 0 Then
ParseValidationError = False
Else
ParseValidationError = True
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment