Public Sub ValidateXML()
'***************************************************************************
'Purpose: Validate the modified xml file against the schema
'Inputs: None
'Outputs: Error display
'***************************************************************************
Dim oxmlSchema As MSXML2.XMLSchemaCache40
Dim oxmlValidateDoc As MSXML2.DOMDocument40
Dim strText As String
Screen.MousePointer = vbHourglass
On Error GoTo ErrorRoutine
'Create the schema cache and add the schema to it.
Set oxmlSchema = New MSXML2.XMLSchemaCache40
oxmlSchema.Add "", frmFileLoc.SchemaLocation & "\" & gstrSchemaName
'Create an XML DOMDocument object.
Set oxmlValidateDoc = New MSXML2.DOMDocument40
'Assign the schema cache to the schemas collection.
Set oxmlValidateDoc.schemas = oxmlSchema
PrettyPrint True
'Load the xml file as the DOM document.
oxmlValidateDoc.async = False
oxmlValidateDoc.Load gstrTempFileName
Screen.MousePointer = vbNormal
'Return validation results in message to the user.
If oxmlValidateDoc.parseError.errorCode <> 0 Then
If oxmlValidateDoc.parseError.errorCode = -2146697210 Then
Err.Raise 1004
Else
' Remove tabs from the text
strText = Replace(oxmlValidateDoc.parseError.srcText, Chr$(9), "")
frmValidate.lblResults.Alignment = vbLeftJustify
frmValidate.lblResults.Caption = _
"Error: " & oxmlValidateDoc.parseError.reason _
& vbCrLf _
& "Found in line number " & oxmlValidateDoc.parseError.Line _
& " line position " & oxmlValidateDoc.parseError.linepos & "." _
& vbCrLf & vbCrLf _
& strText _
& vbCrLf & vbCrLf _
& "(Other errors may be present.)"
frmValidate.imgSad.Visible = True
frmValidate.imgHappy.Visible = False
frmValidate.Show vbModal
frmMain.sbarStatus.Panels(1).Text = "Knowledge base validation failed"
End If
Else
frmValidate.lblResults.Alignment = vbCenter
frmValidate.lblResults.Caption = vbCrLf & vbCrLf _
& "Knowledge base validation passed"
frmValidate.imgSad.Visible = False
frmValidate.imgHappy.Visible = True
frmValidate.Show vbModal
frmMain.sbarStatus.Panels(1).Text = "Knowledge base validation passed"
End If
Set oxmlSchema = Nothing
Set oxmlValidateDoc = Nothing
Exit Sub
ErrorRoutine:
If Err.Number = 1004 Then
MsgBox ResolveResString(resMissingTempFile), _
vbExclamation + vbOKOnly, _
ResolveResString(resErrorTitle, "|1", "Validation")
Else
DisplayError "ValidateXML"
End If
End Sub