miro-s
(Miro Selent)
February 16, 2019, 7:35pm
1
Hi all,
I try to use an XPATH expression to select a text child value from the following XML
<?xml version="1.0" encoding="utf-8"?>
<eta version="1.0" xmlns="http://www.eta.co.at/rest/v1">
<value uri="/user/var/40/10201/0/0/12015" strValue="2431" unit="kg" decPlaces="0" scaleFactor="10" advTextOffset="0">24311</value>
</eta>
The result I’m looking for is “24311”.
In the XPath evaluator I tried (Link ) the expression “/eta/value/text()” worked well. Unfortunately, neither In an OH 2.4 script, nor in an HTTP tranformation I got a result but “”
If i change the same expression to “/eta/value/@scaleFactor ” it works, but that’s not what I’m looking for…
Any idea what I’m doing wrong?
Thanks for your help
Miro
vzorglub
(Vincent Regaud)
February 16, 2019, 7:39pm
2
Can you post these, please?
miro-s
(Miro Selent)
February 16, 2019, 7:57pm
4
sure, but it’s too simple:
For the item:
String Test "Result [%s]" { http="<[http://...:60000:XPATH(/eta/value/text())]" }
And inside a rule:
var xml = sendHttpGetRequest("http://.....")
var result = transform("XPATH","/eta/value/text()", xml)
...
By the way, I solved it with a regexp. But it feels bad and selecting text nodes from XML could be useful in later cases.
rlkoshak
(Rich Koshak)
February 17, 2019, 3:07am
5
I don’t think you need the text(). Does /eta/value work?
miro-s
(Miro Selent)
February 17, 2019, 6:11am
6
No, it doesn’t work. Without /text() it selects the entire element “value” including attributes and so on.