Re: Select specific node and namespaces

Hi Corey,

Coming late to the thread...

> It fails, because objXMLDoc has a namespace, which is not
> represented by the XPath query, so the selectSingleNode call returns
> NULL. However, if I add the namespace before the query:
>
> objXMLDoc.setProperty "SelectionNamespaces", "xmlns:myns="mynamespaceURN"
>
> It still fails unless I modify the XPath to something like:
> /myns:topic[1]/myns:content[1]/myns:para[1]/myns:link[1]
>
> I guess my question is, how can I select a node in this fashion
> without having to modify the Location string so much? I could simply
> replace all the "/" characters with "/myns:" but that just seems
> kludgy. I have a feeling that this is the result of my limited
> experience with XPath.

It's less of a kludge than the other option, which is adjusting your
location path to:

  /*[namespace-uri() = 'mynamespaceURN' and
     local-name() = 'topic'][1]
    /*[namespace-uri() = 'mynamespaceURN' and
       local-name() = 'content'][1]
      /*[namespace-uri() = 'mynamespaceURN' and
         local-name() = 'para'][1]
        /*[namespace-uri() = 'mynamespaceURN' and
           local-name() = 'link'][1]

Don't feel bad about having namespace prefixes in the location path.
It's how XPath works and there's really no getting away from it.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Thursday, 13 June 2002 04:42:29 UTC