Morning all...

I'm having a bit of confusion with using XPath (the XMLSearch()
function) within CFMX.

As far as my limited knowledge of XPath goes, the results from the
XMLSearch() function depends upon the current context, i.e. the root
node being used to "search" against.

Simple XML doc:

<thing>
  <foo>thing</foo>
  <wotsit>
    <foo>wotsit1</foo>
  </wotsit>
  <wotsit>
    <foo>wotsit2</foo>
  </wotsit>
</thing>

This is parsed by CF using xmlparse(), then I do a test xmlsearch() :

<cfdump var="#xmlsearch(parsedxml.XmlRoot, "/thing/foo"#">

Which dumps the "foo" element as expected.

Now if I then do a search to grab the first "wotsit" element:

<cfset wotsit = xmlsearch(parsedxml.XmlRoot, "/thing/wotsit">
<cfset wotsit = wotsit[1]>

I now want to do a query on just this node (this context):

<cfdump var="#xmlsearch(wotsit, "/wotsit/foo"#">

The above doesn't return any results as I would expect?  I thought that
the current context would be the singular "wotsit" node, therefore I
just need to specify the "foo" node I want back.  The following _does_
return results, but seems to do the search from the actual root node
rather than the current context (i.e. it returns BOTH "foo" elements),
whereas I would expect it not to return anything because I'm trying to
use a different context (wotsit, not parsedxml.XmlRoot)?

<cfdump var="#xmlsearch(wotsit, "/thing/wotsit/foo"#">

I can work around this by giving each "foo" element an attribute such
as:

  <wotsit name="1">
    <foo>wotsit1</foo>
  </wotsit>
  <wotsit name="2">
    <foo>wotsit2</foo>
  </wotsit>

And then using an extra bit of XPath:

<cfdump var="#xmlsearch(wotsit,
'/thing/wotsit[@name="#wotsit.XmlAttributes.name#]/foo"#'>

But that seems long winded and kinda defeats the point of using XPath
get at things nice and easily?

Is it just me misunderstanding XPath or is something actually awry?

Tim.


-------------------------------------------------------
Tim Blair
Web Application Engineer, Rawnet Limited
Direct Phone : +44 (0) 1344 393 441
Switchboard : +44 (0) 1344 393 040
-------------------------------------------------------
rawnet ltd
Atrium Court
Bracknell                    [EMAIL PROTECTED]
Berkshire                    Tel : +44 (0) 1344 393 040
RG12 1BW, UK                 http://www.rawnet.com
-------------------------------------------------------
This message may contain information which is legally
privileged and/or confidential.  If you are not the
intended recipient, you are hereby notified that any
unauthorised disclosure, copying, distribution or use
of this information is strictly prohibited. Such
notification notwithstanding, any comments, opinions,
information or conclusions expressed in this message
are those of the originator, not of rawnet limited,
unless otherwise explicitly and independently indicated
by an authorised representative of rawnet limited.
-------------------------------------------------------





-- 
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

Reply via email to