How to select nodes whose parent has a specific attribute

B

bearclaws

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
 
M

Martin Honnen

bearclaws said:
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
 
B

bearclaws

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?
 
M

Martin Honnen

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top