
It then runs an XPath query that uses the contains XPath function to identify all Book titles that contain the word ADO. The preceding code loads the XML from Books.xml into an instance of the MSXML DOMDocument object.

MsgBox "Matching Nodes : " & nlist.lengthĭebug.Print node.nodeName & " : " & node.Text Set nlist = doc.selectNodes("//book/Title") Form1 is created by default.įrom the Project menu, click References, and then select the Microsoft XML 3.0 check box.ĭrag a Command button, and drop it onto Form1.Ĭopy and paste the following code in the Click event procedure of the Command button: Dim doc As MSXML2.DOMDocumentĭoc.setProperty "SelectionLanguage", "XPath" Open a new Standard EXE project in Microsoft Visual Basic. Save Books.xml in the root folder of drive C. In Notepad, create a new XML document named Books.xml, and paste the following XML: This article documents a code sample that demonstrates how you can use the contains XML Path Language (XPath) string function to implement this requirement. When you use the Microsoft XML (MSXML) Document Object Model (DOM) in code to load and parse an XML document, it is common programming practice to identify elements and/or elements with attributes whose data contains a specified string value or word. Original product version: Microsoft XML Original KB number: 304265 Summary This article shows how to use the contains() XPath function when you are programming the MSXML DOM.
