Please Help XML Parsing with XPATH

Tags: #<Tag:0x00007f6173307f60>

Hi can everybody help me i want to prase my xml file from the moehlenhoff heating unit. Now i read any about the xpath transformation but it don´t work correct. Here the code

I have this XML File from the Heating unit

and now the item

String Info “Info [%s]” {http="<[http://192.168.178.29/data/Dynamic.xml:1000:XPATH(/devices/device/HEATAREA nr=[1]/T_ACTUAL]"}

and the sitemap

Text item=Info

i hope anybody can help

Thanks a lot for your solution idea but it don´t work

/Devices/Device/HEATAREA[@nr=‘1’]/T_ACTUAL

Did you try this one?

Yes but Unfortunately it don’t work. In i Wrote /text() at the End for example T_actual/text() then i will See the complete XML in the item but i can‘t select the value. Do you habe a idea what i make wrong

If you copy paste the XML in a code fence then we could actually try to write a working path for you using a online validator like https://www.freeformatter.com/xpath-tester.html

For code fences use tripple quotes or the buttons over the text area.

```
your code goes here
```

Be aware of case sensitivity.

/Devices/Device/HEATAREA[@nr='1']/T_ACTUAL/text()

Maybe something like this, but as said before I could not test it against your real XML.

Maybe?

/*[name()='Devices']/*[name()='Device']/*[name()='HEATAREA']/*[name()='T_ACTUAL']/text()

Could you post your XML, so that we can test, please?

Hi here my XML.

<Devices><Device><ERRORCOUNT>0</ERRORCOUNT><DATETIME>2018-03-28T19:46:53</DATETIME><DAYOFWEEK>3</DAYOFWEEK><TIMEZONE>1</TIMEZONE><TPS>0</TPS><LIMITER>0</LIMITER><CHANGEOVER>0</CHANGEOVER><COOLING>0</COOLING><MODE>0</MODE><ANTIFREEZE_TEMP>8.0</ANTIFREEZE_TEMP><ECO_INPUT_STATE>0</ECO_INPUT_STATE><T_HEAT_VACATION>16.0</T_HEAT_VACATION><VACATION><VACATION_STATE>0</VACATION_STATE><START_DATE>2018-00-00</START_DATE><START_TIME>12:00:00</START_TIME><END_DATE>2018-00-00</END_DATE><END_TIME>12:00:00</END_TIME></VACATION><CLOUD><M2MSTATE>Online</M2MSTATE></CLOUD><KWLCTRL><KWL_CONTROL_VISIBLE>0</KWL_CONTROL_VISIBLE><KWL_PRESENT>0</KWL_PRESENT><KWL_CONNECTION>0</KWL_CONNECTION><KWL_STATUS>0</KWL_STATUS><KWL_FLOWCTRL>0</KWL_FLOWCTRL></KWLCTRL><PUMP_OUTPUT><PUMP_ISACTIVE>1</PUMP_ISACTIVE></PUMP_OUTPUT><RELAIS><RELAIS_ISACTIVE>1</RELAIS_ISACTIVE></RELAIS><HEATAREA nr="1"><HEATAREA_MODE>1</HEATAREA_MODE><T_ACTUAL>22.1</T_ACTUAL><T_ACTUAL_EXT>22.1</T_ACTUAL_EXT><T_TARGET>22.4</T_TARGET><T_TARGET_BASE>22.4</T_TARGET_BASE><HEATAREA_STATE>0</HEATAREA_STATE><PROGRAM_SOURCE>0</PROGRAM_SOURCE><PROGRAM_WEEK>0</PROGRAM_WEEK><PROGRAM_WEEKEND>0</PROGRAM_WEEKEND><PARTY>0</PARTY><PARTY_REMAININGTIME>0</PARTY_REMAININGTIME><PRESENCE>0</PRESENCE><RPM_MOTOR>0</RPM_MOTOR><BLOCK_HC>2</BLOCK_HC><ISLOCKED>0</ISLOCKED><LOCK_AVAILABLE>0</LOCK_AVAILABLE><SENSOR_EXT>0</SENSOR_EXT></HEATAREA><HEATAREA nr="3"><HEATAREA_MODE>0</HEATAREA_MODE><T_ACTUAL>22.2</T_ACTUAL><T_ACTUAL_EXT>22.2</T_ACTUAL_EXT><T_TARGET>22.6</T_TARGET><T_TARGET_BASE>22.6</T_TARGET_BASE><HEATAREA_STATE>0</HEATAREA_STATE><PROGRAM_SOURCE>0</PROGRAM_SOURCE><PROGRAM_WEEK>0</PROGRAM_WEEK><PROGRAM_WEEKEND>0</PROGRAM_WEEKEND><PARTY>0</PARTY><PARTY_REMAININGTIME>0</PARTY_REMAININGTIME><PRESENCE>0</PRESENCE><RPM_MOTOR>0</RPM_MOTOR><BLOCK_HC>2</BLOCK_HC><ISLOCKED>0</ISLOCKED><LOCK_AVAILABLE>0</LOCK_AVAILABLE><SENSOR_EXT>0</SENSOR_EXT></HEATAREA><HEATAREA nr="4"><HEATAREA_MODE>0</HEATAREA_MODE><T_ACTUAL>20.8</T_ACTUAL><T_ACTUAL_EXT>20.8</T_ACTUAL_EXT><T_TARGET>20.0</T_TARGET><T_TARGET_BASE>20.0</T_TARGET_BASE><HEATAREA_STATE>0</HEATAREA_STATE><PROGRAM_SOURCE>0</PROGRAM_SOURCE><PROGRAM_WEEK>0</PROGRAM_WEEK><PROGRAM_WEEKEND>0</PROGRAM_WEEKEND><PARTY>0</PARTY><PARTY_REMAININGTIME>0</PARTY_REMAININGTIME><PRESENCE>0</PRESENCE><RPM_MOTOR>0</RPM_MOTOR><BLOCK_HC>2</BLOCK_HC><ISLOCKED>0</ISLOCKED><LOCK_AVAILABLE>0</LOCK_AVAILABLE><SENSOR_EXT>0</SENSOR_EXT></HEATAREA><HEATAREA nr="5"><HEATAREA_MODE>1</HEATAREA_MODE><T_ACTUAL>21.5</T_ACTUAL><T_ACTUAL_EXT>21.5</T_ACTUAL_EXT><T_TARGET>21.0</T_TARGET><T_TARGET_BASE>21.0</T_TARGET_BASE><HEATAREA_STATE>0</HEATAREA_STATE><PROGRAM_SOURCE>0</PROGRAM_SOURCE><PROGRAM_WEEK>0</PROGRAM_WEEK><PROGRAM_WEEKEND>0</PROGRAM_WEEKEND><PARTY>0</PARTY><PARTY_REMAININGTIME>0</PARTY_REMAININGTIME><PRESENCE>0</PRESENCE><RPM_MOTOR>0</RPM_MOTOR><BLOCK_HC>2</BLOCK_HC><ISLOCKED>0</ISLOCKED><LOCK_AVAILABLE>0</LOCK_AVAILABLE><SENSOR_EXT>0</SENSOR_EXT></HEATAREA><HEATAREA nr="6"><HEATAREA_MODE>0</HEATAREA_MODE><T_ACTUAL>21.3</T_ACTUAL><T_ACTUAL_EXT>21.3</T_ACTUAL_EXT><T_TARGET>22.0</T_TARGET><T_TARGET_BASE>22.0</T_TARGET_BASE><HEATAREA_STATE>0</HEATAREA_STATE><PROGRAM_SOURCE>0</PROGRAM_SOURCE><PROGRAM_WEEK>0</PROGRAM_WEEK><PROGRAM_WEEKEND>0</PROGRAM_WEEKEND><PARTY>0</PARTY><PARTY_REMAININGTIME>0</PARTY_REMAININGTIME><PRESENCE>0</PRESENCE><RPM_MOTOR>0</RPM_MOTOR><BLOCK_HC>2</BLOCK_HC><ISLOCKED>0</ISLOCKED><LOCK_AVAILABLE>0</LOCK_AVAILABLE><SENSOR_EXT>0</SENSOR_EXT></HEATAREA><HEATAREA nr="7"><HEATAREA_MODE>0</HEATAREA_MODE><T_ACTUAL>21.3</T_ACTUAL><T_ACTUAL_EXT>21.3</T_ACTUAL_EXT><T_TARGET>22.6</T_TARGET><T_TARGET_BASE>22.6</T_TARGET_BASE><HEATAREA_STATE>0</HEATAREA_STATE><PROGRAM_SOURCE>0</PROGRAM_SOURCE><PROGRAM_WEEK>0</PROGRAM_WEEK><PROGRAM_WEEKEND>0</PROGRAM_WEEKEND><PARTY>0</PARTY><PARTY_REMAININGTIME>0</PARTY_REMAININGTIME><PRESENCE>0</PRESENCE><RPM_MOTOR>0</RPM_MOTOR><BLOCK_HC>2</BLOCK_HC><ISLOCKED>0</ISLOCKED><LOCK_AVAILABLE>0</LOCK_AVAILABLE><SENSOR_EXT>0</SENSOR_EXT></HEATAREA><IODEVICE nr="1"><SIGNALSTRENGTH>2</SIGNALSTRENGTH><BATTERY>2</BATTERY><IODEVICE_STATE>0</IODEVICE_STATE><IODEVICE_COMERROR>0</IODEVICE_COMERROR><ISON>1</ISON></IODEVICE><IODEVICE nr="2"><SIGNALSTRENGTH>2</SIGNALSTRENGTH><BATTERY>2</BATTERY><IODEVICE_STATE>0</IODEVICE_STATE><IODEVICE_COMERROR>0</IODEVICE_COMERROR><ISON>1</ISON></IODEVICE><IODEVICE nr="3"><SIGNALSTRENGTH>2</SIGNALSTRENGTH><BATTERY>2</BATTERY><IODEVICE_STATE>0</IODEVICE_STATE><IODEVICE_COMERROR>0</IODEVICE_COMERROR><ISON>1</ISON></IODEVICE><IODEVICE nr="4"><SIGNALSTRENGTH>2</SIGNALSTRENGTH><BATTERY>2</BATTERY><IODEVICE_STATE>0</IODEVICE_STATE><IODEVICE_COMERROR>0</IODEVICE_COMERROR><ISON>1</ISON></IODEVICE><IODEVICE nr="6"><SIGNALSTRENGTH>2</SIGNALSTRENGTH><BATTERY>2</BATTERY><IODEVICE_STATE>0</IODEVICE_STATE><IODEVICE_COMERROR>0</IODEVICE_COMERROR><ISON>1</ISON></IODEVICE><IODEVICE nr="7"><SIGNALSTRENGTH>2</SIGNALSTRENGTH><BATTERY>2</BATTERY><IODEVICE_STATE>0</IODEVICE_STATE><IODEVICE_COMERROR>0</IODEVICE_COMERROR><ISON>1</ISON></IODEVICE></Device></Devices>

I have visit the website for test the Xpath Path. Here a Screenshoot i think everythink is right but the path don´t work in Openhab

dynamic.xml (5.3 KB)

In Openhab i see this value in the Item

This is my code

String Info "Info [%s]"{http="<[http://192.168.178.30/data/Dynamic.xml:10:XPATH(/Devices/Device/HEATAREA[@nr='1']/T_ACTUAL/text()]"}

and in the Sitemap

        Frame label= "Info"
        {
            Text item=Info
        }

I don´t know what is wrong ?

The x path openhab transform need a strange syntax.
See the docs
Have you tried the xpath I sent above?

Seems to work for me.

val mytest = transform("XPATH","/Devices/Device/HEATAREA[@nr='1']/T_ACTUAL/text()" ,xml)
logInfo("XML Test","Result:" + mytest)
[INFO ] [ipse.smarthome.model.script.XML Test] - Result:22.1

Did you install the XPATH transformation service?

I have try this one but i have the same problem. If i need the

String Info "Info [%s]"{http="<[http://192.168.178.30/data/Dynamic.xml:10:XPATH(/*[name()='Devices']/*[name()='Device']/*[name()='HEATAREA']/*[name()='T_ACTUAL']/text()]"} 

hi yes xpath transformation service is installed can you give me the right code for openhab items
Thank so lot

You have one space missing, whichis not that tragic.
But there is a ) missing at the end.

String Info "Info [%s]" {http="<[http://192.168.178.30/data/Dynamic.xml:10:XPATH(/Devices/Device/HEATAREA[@nr='1']/T_ACTUAL/text())]"} 

Do you have a look into the logs? Do you use VSCode with openHAB Plugin?

oh Josar thank a lot now its working. I use vsCode wite OH plugin but where can i see the logs. Do you mean the openhab log files ?

can i convert this String to a number without rule

Jop openhab logs, always look at them when saving, errors will be found a lot faster then.

https://docs.openhab.org/administration/logging.html

My setup:

In fact with the http binding it should be possible to just do this.

Number Info "Info [%s]" {http="<[http://192.168.178.30/data/Dynamic.xml:10:XPATH(/Devices/Device/HEATAREA[@nr='1']/T_ACTUAL/text())]"} 

But as it is defined that the transformation has to return a string, i don’t know if it works.

Thanks all a lot for help. Now i want send a command to the heat unit for new temperature Can everybody help me there.
I have a Manual from the manufacter for this

See here: Alpha2-XML-Schnittstellenbeschreibung_de.pdf (475.5 KB)

I think i must created a XML Code in a XML File. Then i must send this to the heatunit. Everybody have a idea for this ?

Thank for all

Hi all!

Can you help me also with the same problem?
I have:

  1. xml file path: http://www.campulverde.info/liveStreams.xml
  2. .items: String Info “Info [%s]” {http="<[http://campulverde.info/liveStreams.xml:10:XPATH(/liveStreams/stream/label/text())]"}
  3. .sitemap: Text item=Info

but I still don’t see my values.

Why?

thx all!

You are trying to get the info every 10ms!