I have been having a problem with XQL returning nothing when that should not be the case. I thought that it might be related to the fact that the nodes it should return have a custom XML namespace (xmlns="...") defined.
I missed the documentation's instructions on using namespaces at first and spent an enormous amount of time on this issue.
Here is an example of how to structure an XQL query in Xojo with a namespace definition:
//Given kXML is a valid XML document with a node named "foo" with xmlns="http://bar.com" Dim theDocument As XmlDocument theDocument = New XmlDocument( kxml ) Dim name As String = "foo" Dim Map() As String Map.Append( "ns1" ) Map.Append( "http://bar.com" ) Dim nodes As XmlNodeList = theDocument.Xql( "//ns1:" + name, URI )
- The "//" at the beginning of the query means at any level in the document.
- To include the namespace in your query, you use the key (in this case, "ns1" but set it to whatever you want) and then a colon before the node name.
- Don't forget to include the array of namespaces that contains any that you reference in your query when you call XMLDocument.XQL as the value for the optional Map() parameter.