Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference | |
Visual Basic Code (item.frm)
Dim er As IXMLDOMParseError2
Dim errs As IXMLDOMParseErrorCollection
Dim xd As New DOMDocument50
Dim xs As New XMLSchemaCache50
' Add xs to xd.
xs.Add "urn:books", App.Path & "\books.xsd"
Set xd.schemas = xs
xd.async = False
xd.validateOnParse = False
xd.setProperty "MultipleErrorMessages", True
' Load the XML file to xd.
xd.Load App.Path & "\books.xml"
' Validate the XML.
Set er = xd.Validate
If er.errorCode <> 0 Then
Set errs = er.allErrors
msg = ""
For i = 0 To errs.length - 1
Set er = errs.item(i)
msg = msg & "errorItem[" & i & "]: " & er.reason & vbCrLf
Next
Else
msg = "DOM is valid:" & vbCrLf & xd.xml
End If
MsgBox msg
Try It!
- Copy the XML data (books.xml), and paste it into a text file. Save the file as books.xml.
- Copy the XSD listing (books.xsd), and paste it into a text file. Save the file as books.xsd in the same directory where you saved books.xml.
- Create a Standard EXE project in Visual Basic. Save the empty project as item.vbp to the same directory where you saved books.xml and books.xsd. Name the form file item.frm.
- Create a reference to MSXML 5.0. To do this, select References... from the Project menu, then check the box for Microsoft XML, v50.
- Copy the Visual Basic code listing above, and paste it into the form_load subroutine.
- Execute the code selecting Start from the Run menu.
- Verify that your output is the same as that listed in the Output for the item Example.