' Check "Microsoft XML, v50" from Project->References... ' in Visual Studio. Set xd = CreateObject("MSXML2.DOMDocument.5.0") Set xs = CreateObject("MSXML2.XMLSchemaCache.5.0") ' Add xs to xd. xs.Add "urn:books", App.Path & "\books.xsd" Set xd.schemas = xs xd.async = False xd.validateOnParse = False xd.Load App.Path & "\books.xml" msg = "Validating DOM..." & vbCrLf Set er1 = xd.Validate If er1.errorCode <> 0 Then msg = msg & "invalid dom:" & vbCrLf & er1.reason _ & "errorXPath:" & vbCrLf & er1.errorXPath & vbCrLf Else msg = msg & "DOM is valid:" & vbCrLf & xd.xml & vbCrLf End If msg = msg & vbCrLf & "Validating nodes..." & vbCrLf Set nlist = xd.selectNodes("//book") For Each node In nlist Set er1 = xd.validateNode(node) If er1.errorCode <> 0 Then msg = msg & vbCrLf & "Node is invalid:" & vbCrLf & er1.reason _ & "errorXPath:" & vbCrLf & er1.errorXPath _ & vbCrLf Else msg = msg & vbCrLf & "Node is valid:" & vbCrLf & node.xml & vbCrLf End If Next MsgBox msg
Try It!