Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
Set objXMLDOMNode =
objXMLDOMElement.selectSingleNode(strXQLQuery)
Remark
Once again, as in the selectNodes() method, selectSingleNode()
uses XQL to find the required Node. However, it only returns a
single Node, XMLDOMNode object, which is the first Node that
matches the pattern if it's found. If no match is found, it
returns NULL.
Example
The selectNodes()
and selectSingle-Node() methods can also be used to search for
Nodes that have certain attribute values. As we mentioned, you
will need to do a bit of research to work out how to work with
XQL, which we do not cover in detail here.
In the following example, we iterate through all the
childNodes in the documentElement collection. We only want to
find the NAME element in each PERSON element.
For Each objXMLDOMNode In
objDOMDocument.documentElement.childNodes
Set objElement =
objXMLDOMNode.selectSingleNode("NAME")
' do something with this name element
Next
Look at getElementsByTagName(), which does almost the same thing as
this method. The beauty of this method, however, is that it
returns a single Node instead of an XMLDOMNodeList. Therefore, this
method is easier to work with, as you don't need to iterate
through a NodeList collection to just get the one value out of
it.
This manuscript is an abridged version of a chapter from the
Manning
Publications book XMLProgramming with VB and ASP. This chapter
looks at the Microsoft DOM objects. NOTE: Most images have been
removed to increase speed and many of the code comments have also
been removed for presentation. Please purchase the book to enjoy
the full experience of all the chapters with images and code
comments!