only My site

Tuesday, July 22, 2008

Contains() XPath Function in MS DOM

<?xml version="1.0"?>

<!-- This file represents a fragment of a bookstore inventory database -->

<bookstore specialty="novel">

<book>

<Title>Beginning XML</Title>

<Publisher>Wrox</Publisher>

</book>

<book>

<Title>Professional XML</Title>

<Publisher>Wrox</Publisher>

</book>

<book>

<Title>Programming ADO</Title>

<author>

<first-name>Mary</first-name>

<last-name>Bob</last-name>

</author>

<datePublished>1/1/2000</datePublished>

<Publisher>Microsoft Press</Publisher>

</book>

</bookstore>



Add References, by selecting the Microsoft XML 3.0 check box.

Dim doc As MSXML2.DOMDocument
Dim nlist As MSXML2.IXMLDOMNodeList
Dim node As MSXML2.IXMLDOMNode

Set doc = New MSXML2.DOMDocument
doc.setProperty "SelectionLanguage", "XPath"
doc.Load "c:\books.xml"
Set nlist = doc.selectNodes("//book/Title[contains(.,'ADO')]")
MsgBox "Matching Nodes : " & nlist.length

For Each node In nlist
Debug.Print node.nodeName & " : " & node.Text
Next

Source : http://support.microsoft.com/kb/304265

No comments: