Last active
March 9, 2023 11:02
-
-
Save adojos/ddcd8fb90b737827f2ce4058f4a5655f to your computer and use it in GitHub Desktop.
VBS: Parse XSD Validation Errors #vbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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