From below XML I want to extract Mobile_Number
values which is under values/value
tag. How can I make this generic, because we can have multiple options later on instead of single Mobile_Number
option.
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<header>
<businessTransactionID>ABCD</businessTransactionID>
<externalCorrelationID>UABCD</externalCorrelationID>
<sentTimestamp>2016-12-23T14:21:11.261+01:00</sentTimestamp>
<sourceContext>
<host>stackoverflow</host>
<application>browser</application>
<operation>ExtractXMLTAGVALUE</operation>
</sourceContext>
</header>
<body>
<serviceCharacteristic>
<specification>
<ID>Mobile_Number</ID>
</specification>
<values>
<value>13008421</value>
</values>
</serviceCharacteristic>
</body>
</Request>
I tried below XPath queries but in vain:
//*[local-name()='name'][text()='Mobile_Number']/../*[local-name()='value']/text()
Below query will work but then again it is not on the basis of ID value which is Mobile_Number
-
string(/*/*/*[local-name()='serviceCharacteristic']/*/*[local-name()='value'])
How about this?