OH3: Reading XML-File

  • Platform information:
    • Hardware: Raspi 4
    • OS: OH3, http in Docker, Linux
    • Binding HTTP installed

Dear experts,
i need a little help for configuration via OH3-GUI reading xml-file.

This is my configuration:

UID: http:url:c94a0df2ed
label: 001-HTL_STE_XML
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: true
baseURL: http://:40080/
refresh: 30
commandMethod: GET
contentType: text/xml
timeout: 3000
bufferSize: 2048
channels:

  • id: XML_Status
    channelTypeUID: http:string
    label: XML-Status
    description: “”
    configuration:
    mode: READONLY
    stateExtension: HBData_Test.xml
    stateTransformation: XPath://dataroot/AbfReservation/Status

item:
426_HTL_STE_XML
State Description with 0=xy, 1=zx, 2=ss
Channel Links to 001-HTL_STE_XM (String, Point)

XML-File: HBData_Test.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2021-03-24T16:25:02">
  <AbfReservation>
    <Anreise>2021-03-24T00:00:00</Anreise>
    <Abreise>2021-03-26T00:00:00</Abreise>
    <ZNr>426</ZNr>
    <Name>dispo-Tf Education GmbH</Name>
    <ERWACHSEN>1</ERWACHSEN>
    <Status>3</Status>
    <STYLE>1</STYLE>
    <GASTNR>119059</GASTNR>
    <Uhrzeit>16:25:02</Uhrzeit>
  </AbfReservation>
</dataroot>

With webvievw-item it is possible present the file HBData_tes.xml

I get no value from HBData_test.xml and no info in event.log.

That looks suspect (not XPATH) does your openhab.log have anything to say about it?

yes, I found an error:

[WARN ] [.transform.SingleValueTransformation] - Executing transformation ChannelStateTransformation{pattern=’//dataroot/AbfReservation/Status’, serviceName=‘XPATH’} failed: transformation throws exceptions

also i checked the xml with XPath Tester / Evaluator; the result is

<Status>3</Status>

Hello,
no more tips or discussion about this problem here?

  • what means: transformation throws exceptions

“Something went wrong”. It’s not very helpful to us.

When experimenting with transformations, I find it useful to set up a little rule to check and test things.
So I tried with your data -

val rawxml='<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2021-03-24T16:25:02">
  <AbfReservation>
    <Anreise>2021-03-24T00:00:00</Anreise>
    <Abreise>2021-03-26T00:00:00</Abreise>
    <ZNr>426</ZNr>
    <Name>dispo-Tf Education GmbH</Name>
    <ERWACHSEN>1</ERWACHSEN>
    <Status>3</Status>
    <STYLE>1</STYLE>
    <GASTNR>119059</GASTNR>
    <Uhrzeit>16:25:02</Uhrzeit>
  </AbfReservation>
</dataroot>'
var results = transform("XPATH", "//dataroot/AbfReservation/Status", rawxml)
logInfo("test", " simple path " + results)

and got the result

2021-04-13 00:16:47.268 [INFO ] [.eclipse.smarthome.model.script.test] -  simple path 3

so it looks like your parameters are good.

What’s gone wrong then?
Maybe you don’t get back the XML that you expected.

Set up another temporary string type channel on your HTML Thing, link it to a String type Item and examine the whole message.
Your baseURL looks suspect to me.

Next try and error:

Without the “stateTransformation: XPath://dataroot/AbfReservation/Status” i get the hole XML-File to string item.

Yes, that was the whole idea of making a temporary String Item, so that you can check the message.
What is the error please?

now i’m edit the xml-file string by string … and the state is correct!!

some special characters within the file… ???

I don’t understand what you are doing. Why not test your XPATH on the whole string in a rule, like my test.

1 Like