Private Sub Command1_Click()
Dim xmlschema As MSXML2.XMLSchemaCache40
Dim xmldom As MSXML2.DOMDocument40
Set xmlschema = New MSXML2.XMLSchemaCache40
xmlschema.Add "", "C:\D-drive\HELP_Temp\EMohan\ASNViewer\GenSchema.xsd"
Set xmldom = New MSXML2.DOMDocument40
xmldom.async = False
Set xmldom.schemas = xmlschema
xmldom.Load "C:\D-drive\HELP_Temp\EMohan\ASNViewer\Pradeep.xml"
If xmldom.parseError.errorCode <> 0 Then
MsgBox xmldom.parseError.errorCode & " " & xmldom.parseError.reason
Else
MsgBox "No Error"
End If
Set xmldom = Nothing
Set xmlschema = Nothing
End Sub
Public Sub ValidateXML()
'***************************************************************************
'Purpose: Validate the modified xml file against the schema
'Inputs: None
'Outputs: True if OK, False if not.
'***************************************************************************
Dim oxmlSchema As MSXML2.XMLSchemaCache40
Dim oxmlValidateDoc As MSXML2.DOMDocument40
Dim strText As String
On Error GoTo ErrorRoutine
'Create the schema cache and add the schema to it.
Set oxmlSchema = New MSXML2.XMLSchemaCache40
oxmlSchema.Add "", "C:\D-drive\HELP_Temp\EMohan\ASNViewer\GenSchema.xsd"
'Create an XML DOMDocument object.
Set oxmlValidateDoc = New MSXML2.DOMDocument40
'Assign the schema cache to the schemas collection.
Set oxmlValidateDoc.schemas = oxmlSchema
'Load the xml file as the DOM document.
oxmlValidateDoc.async = False
oxmlValidateDoc.Load "C:\D-drive\HELP_Temp\EMohan\ASNViewer\good.xml"
'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.Show vbModal
End If
Else
frmValidate.lblResults.Alignment = vbCenter
frmValidate.lblResults.Caption = vbCrLf & vbCrLf _
& "Knowledge base validation passed"
frmValidate.Show vbModal
End If
Set oxmlSchema = Nothing
Set oxmlValidateDoc = Nothing
Exit Sub
ErrorRoutine:
If Err.Number = 1004 Then
MsgBox "Error"
'MsgBox ResolveResString(resMissingTempFile), _
' vbExclamation + vbOKOnly, _
' ResolveResString(resErrorTitle, "|1", "Validation")
Else
'DisplayError "ValidateXML"
MsgBox "Valid"
End If
End Sub
Private Sub Command2_Click()
ValidateXML
End Sub