Please Help XML Parsing with XPATH

xpath
Tags: #<Tag:0x00007f1e5bca1d60>
(Vincent Regaud) #25

Try that:
This will check if we get any data at all

String Info "Info [%s]" {http="<[http://campulverde.info/liveStreams.xml:60000:default]"}
0 Likes

(Matei Garici) #26

thx but it makes no difference :frowning:

0 Likes

(Vincent Regaud) #27

I now have:

String Info "Info [%s]" { http="<[http://campulverde.info/liveStreams.xml:60000:XPATH(/liveStreams/stream/label/text())]" }

I have tried with t full regex and It got the data
I have checked the XPATH in https://www.freeformatter.com/xpath-tester.html#ad-output
and your XPATH is correct
I don’t know why it doesn’t work

0 Likes

(Josar) #28

@gsmatei and @vzorglub The xpath does not work as it does not address the namespace.

https://docs.openhab.org/addons/transformations/xpath/readme.html

0 Likes

(Matei Garici) #29

thx @vzorglub!!!

@Josar

Starting from the example in your link:

String Temperature_xml “Temperature [JSONPATH([name()=‘PTZStatus’]/[name()=‘AbsoluteHigh’]/[name()=‘azimuth’]/):%s °C]” {…}

i’ve tried with this but it’s not working:

String Info “Info [JSONPATH([name()=‘liveStreams’]/[name()=‘stream’]/[name()=‘label’]/) %s]” {http="<[http://campulverde.info/liveStreams.xml]"}

What I’m doing wrong?

thx!

0 Likes

(Josar) #30

Documentation has an typo JSONPATH vs XPATH

0 Likes

(Matei Garici) #31

:)))

Still something else is wrong with that example. Look what i get:

with this: String Info “Info [XPATH([name()=‘liveStreams’]/[name()=‘stream’]/[name()=‘label’]/) %s]” {http="<[http://campulverde.info/liveStreams.xml]"}

0 Likes

(Josar) #32

you have to give a closer look :wink:

there is something missing " : "

azimuth’]/):%s °C]

0 Likes

(Matei Garici) #33

I added “:”. Still no difference then the last print screen :frowning:

0 Likes

(Josar) #34
[name()='PTZStatus']/*[name()='AbsoluteHigh']/*[name()='azimuth']/):%s °C]

vs

[name()='liveStreams']/[name()='stream']/[name()='label']/) %s]

you could try it with

String Info "Info [XPATH(/*[name()='liveStreams']/*[name()='stream']/*[name()='label']/):%s]" {...}
0 Likes

(Josar) #35

@gsmatei and using code fences makes reading the post a lot easier.

1 Like

(Matei Garici) #36

Sorry for not using code fences.

Nope, still not working with the same code from you :frowning:

String Info "Info [XPATH(/*[name()='liveStreams']/*[name()='stream']/*[name()='label']/):%s]"  {http="<[http://campulverde.info/liveStreams.xml]"}

0 Likes

(Josar) #37

But you have installed the XPATH transformation!

What does the log say?

0 Likes

(Josar) #38

@gsmatei this works

String http_Info "Info [%s]" {http="<[http://campulverde.info/liveStreams.xml:60000:XPATH(/*[name()='liveStreams']/*[name()='stream']/*[name()='label'])]"}
2 Likes

(Matei Garici) #39

Looks like it’s installed.

Log file says:

2018-05-07 15:46:22.416 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'http' of item 'Info' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: bindingConfig 'http://campulverde.info/liveStreams.xml' doesn't represent a valid in-binding-configuration. A valid configuration is matched by the RegExp '(.*?)(\{.*\})?:(?!//)(\d*):(.*)'
	at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[176:org.openhab.core.compat1x:2.1.0]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:325)[123:org.eclipse.smarthome.model.item:0.9.0.b5]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:297)[123:org.eclipse.smarthome.model.item:0.9.0.b5]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:182)[123:org.eclipse.smarthome.model.item:0.9.0.b5]
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:367)[123:org.eclipse.smarthome.model.item:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:286)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:136)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:234)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:297)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.core.service.WatchQueueReader.run(WatchQueueReader.java:206)[98:org.eclipse.smarthome.core:0.9.0.b5]
	at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]

0 Likes

(Matei Garici) #40

Yes!!! Now it’s working!!!

String http_Info "Info [%s]" {http="<[http://campulverde.info/liveStreams.xml:60000:XPATH(/*[name()='liveStreams']/*[name()='stream']/*[name()='label'])]"}

Super thx!!!

0 Likes

(Vincent Regaud) #41

Thanks, I was basically copying the one use for openhab service
Learned something, always good

0 Likes

(Josar) #42

Just as an additional information, there is/was a bug in the label transformation. But it schould be fixed in future reaeases.
Thats why the transformation had to be done at the binding which is a better solution if the content of the xml is not needed anywhere else, imho.

0 Likes

( ) #43

Hey!

I´d like to receive the current tv show via xml, this expression would normaly return me the current running tv-show on that specific channel 'ARD':

string(/rss/channel/item[dc:subject='ARD']/title)

With the help of this post, I was able to create an Item which returns me the channel name as result, as expected. But how can I add the value that I´m searching for 'ARD' and the desired output value in the field <title>?

String      TV_Channel_ARD_CurrentShow      "Aktuell laeuft [%s]"     { http="<[http://www.texxas.de/tv/hauptsenderJetzt.xml:3600000:XPATH(/*[name()='rss']/*[name()='channel']/*[name()='item']/*[name()='dc:subject'])]"}
0 Likes

(Marco Badano) #44

i have a similar problem:
i have this register:


whit this string:

String dato “Info [%s]” {http="<[http://192.168.1.115/7:6000:XPATH(/[name()=‘modbusregisters’]/[name()=‘register’]/*[name()=‘value’])]"}

but doesn’t work can anyone help me please?

0 Likes