Does anyone know how I can validate an XML document against an XSD document in VB6?
Printable View
Does anyone know how I can validate an XML document against an XSD document in VB6?
VB Code:
Public Sub LoadFile(strTargetFile As String) '*************************************************************************** 'Purpose: Perform actions necessary to load the target xml file 'Inputs: strTargetFile - The name of the xml file to be opened. 'Outputs: None '*************************************************************************** Dim lngIndex As Long On Error GoTo ErrorRoutine XMLdoc.async = False XMLdoc.validateOnParse = False XMLdoc.preserveWhiteSpace = False XMLdoc.Load strTargetFile If XMLdoc.parseError.errorCode = 0 Then If XMLdoc.readyState = 4 Then ' It's OK 'AddNodeToTree XMLdoc.documentElement End If Else Err.Description = XMLdoc.parseError.reason & vbCrLf & _ "Line: " & XMLdoc.parseError.Line & vbCrLf & _ "XML: " & XMLdoc.parseError.srcText Err.Raise 1006 End If Exit Sub ErrorRoutine: ' You would have your own error display here 'DisplayError "LoadFile" End Sub
I should note that this only works with MSXML 4 and newer. Previous versions of MSXML used a Microsoft proprietary version of XSD. Other than that, this code works great - I've used it a couple of times. That's how I found out about the MSXML 4 thing, we were still using 3 at the time and kept getting an error loading the XSD into the schema, even though there wasn't anything wrong with it. Finaly found the answer after scouring MSDN for nearly a week. It was in some obscure text tucked away in tiny print as an "oh, yeah, and by the way...." grrrr.
TG