I have a sample xml file which looks like the one below:
<Root>
<SubOne>
<book author="george" />
<indiv name="abc" />
<indiv name="khh" />
<indiv name="ioo" />
</SubOne>
<SubTwo>
<indiv book author="hamle" />
<indiv name="kok"/>
<indiv name="ppp" />
</SubTow>
</Root>
Is there a way in XPATH to check , if author=”george” select /Root/SubOne/indiv/@name , or if the author=”hamle”, select /Root/SubTwo/indiv/@name.
Any help is appreciated
First I noticed that your
XMLis not valid.Assume that your XML is as follows.
XML:
XPATH:
For
@author='george', use this XPATH:For
@author='hamle', use this XPATH:For both XPATH, to print the name use
@nameJAVA:
Using Java, you need to implement this way for both xpath’s
For
@author='george',For
@author='hamle',