Page 1 of 1

Confusing XPath problem

Posted: Fri Jan 06, 2006 12:29 pm
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

illness

Posted: Mon Jan 23, 2006 12:35 pm
by eHannes
try: //Name[following-sibling::Symptoms/Symptom[.='weakness']]