Confusing XPath problem

Questions about XML that are not covered by the other forums should go here.
the_dude
Posts: 1
Joined: Fri Jan 06, 2006 12:16 pm

Confusing XPath problem

Post by the_dude »

Hi all

I am having problems with extracting some thing out of one xml file. Please have a look at it.

Code: Select all


<diseases>
<disease>
<DocumentName>lungcancer</DocumentName>
<Name>lung cancer</Name>
<Symptoms>
<Symptom number="1">coughing blood</Symptom>
<Symptom number="2">weakness</Symptom>
</Symptoms>
</disease>
<disease>
<DocumentName>pneumonia</DocumentName>
<Name>pneumonia</Name>
<Symptoms>
<Symptom number="1">inflammation of lungs</Symptom>
<Symptom number="2">weakness</Symptom>
</Symptoms>
</disease>
</diseases>
Now I want to extract node "Name" if there is Symptom "weakness". So the answer should be "lungcancer" and "pneumonia". But I can't figure out what the XPath query should be. Can anyone please help me?

How to go up one or more than one level in xpath. For one level, getParentNode() works. But what about more than one level?

Thanks
eHannes
Posts: 31
Joined: Sat Apr 16, 2005 11:29 am

illness

Post by eHannes »

try: //Name[following-sibling::Symptoms/Symptom[.='weakness']]
Post Reply