473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to select nodes whose parent has a specific attribute

I want to select certain nodes from an XML file whose parent nodes
contain a particular attribute id.

For instance, here's a sample XML file:

<AAA>
<BBB id="111">text
<CCC>text</CCC>
</BBB>
<BBB id="222">
<CCC>text</CCC>
</BBB>
</AAA>

....and I want to loop through "AAA" and get all "CCC" nodes whose
parents id is "111".

How do I do this?

Thanks,
BC

Jul 20 '05 #1
4 1825


bearclaws wrote:
I want to select certain nodes from an XML file whose parent nodes
contain a particular attribute id.

For instance, here's a sample XML file:

<AAA>
<BBB id="111">text
<CCC>text</CCC>
</BBB>
<BBB id="222">
<CCC>text</CCC>
</BBB>
</AAA>

...and I want to loop through "AAA" and get all "CCC" nodes whose
parents id is "111".


XPath expression is
/AAA/*[@id = '111']/CCC

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Thanks but I left out the confusing part (sorry)...

I want to loop through "AAA" and get all "CCC" nodes whose parents id
is "111"...AND whose parents node value is "text".

I'm not sure how to combine both an attribute and a value condition.

Thoughts?

Jul 20 '05 #3


bearclaws wrote:

I want to loop through "AAA" and get all "CCC" nodes whose parents id
is "111"...AND whose parents node value is "text".


Then perhaps the XPath expression is
/AAA/*[@id = '111' and text()[1] = 'text']/CCC
but there are many different views of what the node value is so I am not
sure that will select what you are looking for.

You might want to look at tutorials like
<http://www.w3schools.com/xpath/default.asp>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
Many thanks! This worked great :)
BC


Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Timo Nentwig | last post by:
Hi! I want to select the parent of <span class="h2"> (which is <td>). The following does not work: //span/../td <blah> <td> <span class="h2" />
3
by: Michael Reiche | last post by:
Question on XSL expression Got this XML: <Body> <Page> <Line no="9" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line>
6
by: Nikhil Patel | last post by:
Hi all, Following is a portion of an XML document. I need to remove all nodes that belong to ns0 without deleting their child nodes. So in the following example , I want to delete "ns0:Proposal"...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
16
by: Brian D | last post by:
I have a multiple select list that is created dynamically based on a previous selection on an asp page. The first thing I do is to clear the curent option list by ...
2
by: npm | last post by:
I'm trying to display XML nodes whose parent node has a certain attribute (or attribute value). I have one code that works in Firefox, but not IE and another code that works in IE, but not Firefox. ...
0
by: empiresolutions | last post by:
Howdy, I have an PHP page that edits XML files. I want ADD a new *id* attribute to all nodes on the page that do not have it all ready. Then i want to delete all of the values of *id* and set...
1
by: empiresolutions | last post by:
Howdy, I have an PHP page that edits XML files. I want ADD a new *id* attribute to all nodes on the page that do not have it all ready. Then i want to delete all of the values of *id* and set...
5
by: AdrianGawrys | last post by:
Hi Guys, I have an xml similar to this one: <?xml version="1.0" encoding="UTF-8"?> <SystemUpdate ForceUpdate="false" > <A ForceUpdate="false"> <Book name="Black" /> <Book...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.