get value from XML( a, b, c, d )
Group |
Returns the first result value of the XPath expression b on the XML object a. Optionally, an XPath expression can be created from the values b and c. Also, it is possible to set specific namespaces using a map, which can be defined in parameter d. Existing namespaces with the same name will be replaced. If a list name is specified in e, all values returned by the XPath query are added to the list. The first value of the XPath query is returned. Values previously stored in the list are not deleted. A default list name is not used if no list name is provided.
Description of Parameters
Parameter |
Description |
a |
Name of XML object. You can obtain such an object by using the function parse XML( a, b, c ). |
b |
XPath expression (Selection of a specific set of nodes). |
c |
(optional) XPath expression. |
d |
(optional) Name of the map for the namespace management. |
e |
(optional) Name of the list to store XPath query results into. Default: empty. |
Examples
Example 1:
Given is the following XML file, which we first read in under the name xml_Invoice with function parse XML( a, b, c ). We can then use this name in parameter a of this function here.
<
Invoice
>
<
Invoice_number
>INV_12345</
Invoice_number
>
<
Invoice_date
>2014-05-21T15:25:11Z</
Invoice_date
>
<
Customer
>
<
Customer_number
>12345</
Customer_number
>
<
First_name
>Gustav</
First_name
>
<
Last_name
>Thalmeier</
Last_name
>
<
City
>Treuchtlingen</
City
>
<
DOB
>15.07.1981</
DOB
>
<
Order
>
<
Article_number
id
=
"123689"
>DE459363258</
Article_number
>
<
Quantity
>1</
Quantity
>
<
Price
>17,98</
Price
>
</
Order
>
<
Order
>
<
Article_number
id
=
"5896324"
>459363298</
Article_number
>
<
Quantity
>1</
Quantity
>
<
Price
>4,99</
Price
>
</
Order
>
</
Customer
>
<
Customer
>
<
Customer_number
>85639</
Customer_number
>
<
First_name
>Henriette</
First_name
>
<
Last_name
>Michlmeier</
Last_name
>
<
City
>Breckerfeld</
City
>
<
DOB
>04.12.1975</
DOB
>
<
Order
>
<
Article_number
id
=
"9832475"
>DE459362358</
Article_number
>
<
Quantity
>1</
Quantity
>
<
Price
>199,59</
Price
>
</
Order
>
<
Order
>
<
Article_number
id
=
"123659"
>459363258</
Article_number
>
<
Quantity
>3</
Quantity
>
<
Price
>7,99</
Price
>
</
Order
>
<
Order
>
<
Article_number
id
=
"123689"
>DE459363258</
Article_number
>
<
Quantity
>1</
Quantity
>
<
Price
>14,99</
Price
>
</
Order
>
</
Customer
>
</
Invoice
>
If a list name is specified in parameter e, we assume the list to be empty.
Parameter a |
Parameter b |
Parameter c |
Parameter d |
Parameter e |
Result |
Elements of the List |
xml_Invoice |
/NonExist |
|
|
|
|
|
xml_Invoice |
/Invoice[1]/Invoice_date |
|
|
|
2014-05-21T15:25:11Z |
|
xml_Invoice |
/Invoice_number |
/Invoice[1] |
|
|
INV_12345 |
|
xml_Invoice |
/Invoice[1]/Customer[1]/Customer_number |
|
|
|
12345 |
12345 |
xml_Invoice |
/Invoice[1]/Customer[2]/Customer_number |
|
|
|
85639 |
|
xml_Invoice |
//Customer_number |
|
|
|
12345 |
|
xml_Invoice |
//Customer_number |
|
|
custList |
12345 |
12345, 85639 |
Example 2:
Given is the following XML file, which we first read in under the name xml_ConversionRate with function parse XML( a, b, c ). We can then use this name in parameter a of this function here.
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
soap
:Envelope
xmlns:soap
=
"http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd
=
"http://www.w3.org/2001/XMLSchema"
xmlns:conversionrate
=
"http://www.example.com"
>
<
soap
:Body>
<
ConversionRateResponse
xmlns
=
"http://www.webserviceX.NET/"
>
<
ConversionRateResult
>309.09</
ConversionRateResult
>
<
ConversionRateResult
>22.15</
ConversionRateResult
>
<
conversionrate
:Date>2017-04-03</
conversionrate
:Date>
</
ConversionRateResponse
>
</
soap
:Body>
</
soap
:Envelope>
Note: To be able to use the value of tag ConversionRateResult, a map with the namespace dw_dflt=http://www.webserviceX.NET/ has to be defined. To find results, the XPath expression has to use the respective prefix.
The map can be used to simplify namespace names.
Assume the following map for the examples:
dw_dflt=http://www.webserviceX.NET/
cr=http://www.example.com
s=http://www.w3.org/2003/05/soap-envelope
Parameter a |
Parameter b |
Parameter c |
Parameter d |
Parameter e |
Result |
Elements of the List |
xml_ConversionRate |
/NonExist |
|
|
|
|
|
xml_ConversionRate |
/Envelope[1]/Body[1]/ConversionRateResponse[1]/ConversionRateResult |
|
|
|
empty (see note above) |
|
xml_ConversionRate |
/soap:Envelope[1]/soap:Body[1]/ConversionRateResponse[1]/ConversionRateResult |
|
|
|
empty (see note above) |
|
xml_ConversionRate |
/soap:Envelope[1]/soap:Body[1]/dw_dflt:ConversionRateResponse[1]/dw_dflt:ConversionRateResult[1] |
|
map_namespaces |
|
309.09 |
|
xml_ConversionRate |
//dw_dflt:ConversionRateResult |
|
map_namespaces |
|
309.09 |
|
xml_ConversionRate |
/dw_dflt:ConversionRateResponse[1]/dw_dflt:ConversionRateResult |
/soap:Envelope[1]/soap:Body[1] |
map_namespaces |
list_ConversionRate |
309.09 |
309.09,22.15 |
xml_ConversionRate |
/soap:Envelope[1]/soap:Body[1]/dw_dflt:ConversionRateResponse[1]/conversionrate:Date[1] |
|
|
|
2017-04-03 |
|
xml_ConversionRate |
/s:Envelope[1]/s:Body[1]/dw_dflt:ConversionRateResponse[1]/cr:Date |
|
map_namespaces |
|
2017-04-03 |
|
Please note that in the case of XML files with namespaces, the namespace must also be specified in the Xpath expression.