Reputation: 1595
I'm using Java and import javax.xml.xpath.*
package.
I'm a beginner with XPATH and I can not recover a value based on another value.
Here my .xml file
<lom:lom xmlns:lom="http://ltsc.ieee.org/xsd/LOM" xmlns:lomfr="http://www.lom-fr.fr/xsd/LOMFR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<lom:general>
...
<lom:title>
<lom:string language="fre">Analyse financière bilan : Un exemple d'approche financière par la méthode des ratios - la centrale de bilans de la Banque de France</lom:string>
</lom:title>
...
</lom:general>
<lom:lifeCycle>
...
<lom:contribute>
<lom:role>
<lom:source>LOMv1.0</lom:source>
<lom:value>author</lom:value>
</lom:role>
<lom:entity>BEGIN:VCARD VERSION:3.0 N:GARROT;Thierry;;; FN:Thierry GARROT EMAIL;TYPE=INTERNET:thierry.garrot@unice.fr ORG:Université de Nice END:VCARD</lom:entity>
<lom:date>
<lom:dateTime>2009-10-07</lom:dateTime>
</lom:date>
</lom:contribute>
<lom:contribute>
<lom:role>
<lom:source>LOMv1.0</lom:source>
<lom:value>instructional designer</lom:value>
</lom:role>
<lom:entity>BEGIN:VCARD VERSION:3.0 N:CASANOVA;Gérard;;; FN:Gérard CASANOVA EMAIL;TYPE=INTERNET:gerard.casanova@univ-nancy2.fr ORG:Université de Lorraine END:VCARD</lom:entity>
<lom:date>
<lom:dateTime>2009-10-07</lom:dateTime>
</lom:date>
</lom:contribute>
<lom:contribute>
...
</lom:contribute>
...
</lom:lifeStyle>
</lom>
How can I get lom:entity
value only if lom:value
value is author
?
lom:entity
is a VCARD but I think that it's a problem because I have an algorithm to get author fullname.
Example:
To get lom:title
I use : //*[local-name()='title']/*[local-name()='string']/text()
.
Thank's for help!
Upvotes: 2
Views: 52
Reputation: 29052
The XPath expression you are looking for is (expecting a proper namespace handling):
/lom:lom/lom:lifeCycle/lom:contribute[lom:role/lom:value = 'author']/lom:entity
This should give you the desired content.
A namespace ignoring variant of the above XPath expression is
/*[local-name()='lom']/*[local-name()='lifeCycle']/*[local-name()='contribute'][*[local-name()='role']/*[local-name()='value'] = 'author']/*[local-name()='entity']
Upvotes: 2
Reputation: 92894
How can I get
lom:entity
value only iflom:value
value isauthor
?
xpath
expression:
//lom:entity[parent::lom:contribute/lom:role/lom:value="author"]/text()
Upvotes: 1