• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Parent node of an XML Search

Guest
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

I have been wrecking my brain on this and I am sure that it is possible I am just not sure what the proper search expression is.

If I have an XML document like this:
<items>
<item>
<linkurl>foo</linkurl>
<item>
<linkurl>bar</linkurl>
</item>
</item>
</items>

Lets say I am looking for the parent of the item element that has a linkurl element with value of "bar" I would expect to write something like this:

<cfset itemArray = xmlSearch(xmlDoc, "ancestor:://item[linkurl='bar']")>

I know that for this particular instance I could access it directly but in my case there may be many <item> tags nested so I want it to be dynamic so that I can continue to walk back up the tree.

Any help will be appreciated
TOPICS
Advanced techniques

Views

419

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
May 11, 2006 May 11, 2006
This was posted a couple of times because of a bad internet connection, anyways with my trusty XPath Explorer plugin I was able to get the solution:

<cfset itemArray = xmlSearch(xmlDoc, "//item[linkurl='bar']/parent::item")>

If you have started to play with XML and XPath in particular and you are using Eclipse the XPath Explorer plugin is invaluable!

Votes

Translate

Translate
Guest
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

LATEST
This was posted a couple of times because of a bad internet connection, anyways with my trusty XPath Explorer plugin I was able to get the solution:

<cfset itemArray = xmlSearch(xmlDoc, "//item[linkurl='bar']/parent::item")>

If you have started to play with XML and XPath in particular and you are using Eclipse the XPath Explorer plugin is invaluable!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation