Any working examples of XMLnode.XQL?

The documentation is rather terse :slight_smile: on this subject. Can you point me to a short example of use of the XQL method in XMLNode.


This is mostly lifted from the old email NUG list archives
Suppose you have XML like

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <radio> <programme> <title>Paul Temple and the Jonathan Mystery</title> <author>Francis Durbridge</author> <genre type="serial" length="30" episodes="8">mystery</genre> </programme> <programme> <title>The Elephant Man</title> <author>Bernard Pomerance</author> <genre type="play" length="90">drama</genre> </programme> </radio>

and its in a variable called tXML

The “programme” node is a child of the “radio” node, so you need to drill down the tree in order to find it.
There are two major ways to do this:

  1. use the descendant operator ("//"), which will find the target node anywhere in the tree
    i.e. tXML.xql("//programme")

dim tXML as XmlDocument = new XmlDocument( untitled ) dim node as XMLNodeList = tXML.xql("//programme")

  1. set a base node, and then query it

// no error checking here at all for simplicity’s sake!
dim radioNode as XMLNode
radioNode = xdoc.xql( “radio” ).Item(0) // no error checking to see if the item exists!!
// radioNode is now an XMLNode

dim programmeList as XMLNodeList
programmeList = radioNode.xql( “programme” )

// bare minimal error checking
dim programme as XMLNode
if programmeList.Length > -1 then programme = programmeList.Item(0)[/code]

I have been using the xql method and it seems reliable at returning node lists.
But what I am having trouble doing is checking to see if the node is the node i’m looking for in the node list.

The XQL docs have a short example and a link to references on more about XQL/XPath in general:

How are you trying to identify the node, and what is it doing/not doing?

Note that a node’s tag is in the node itself, and its value is in a child node. So if you’re looking for a node like


your code would look like

if ( = “tag1” and node.firstchild.value = “value1”) then