XPpath-parsing leads to zero output

Hi there,
I am having a problem with parsing an xml-document with XPath via http. My document looks like this (output truncated):

<?xml version="1.0" encoding="UTF-8"?>
  <Device Name="Inverter" NominalPower="5000" Type="Inverter" Serial="XXX" BusAddress="X" NetBiosName="XXX" IpAddress="" DateTime="2018-07-25T19:15:22">
      <Measurement Value="3414.9" Unit="W" Type="AC_Power"/>
      <Measurement Value="1140.4" Unit="W" Type="AC_Power1"/>
      <Measurement Value="1140.2" Unit="W" Type="AC_Power2"/>
      <Measurement Value="1136.5" Unit="W" Type="AC_Power3"/>
      <Measurement Value="49.989" Unit="Hz" Type="AC_Frequency1"/>
      <Measurement Value="49.998" Unit="Hz" Type="AC_Frequency2"/>
      <Measurement Value="49.998" Unit="Hz" Type="AC_Frequency3"/>
      <Measurement Value="49.9" Unit="°C" Type="Temp"/>
      <Measurement Value="4409.3" Unit="W" Type="GridPower"/>
      <Measurement Value="100.0" Unit="%" Type="Derating"/>

I am inetressted in the values of “AC Power” and “GridPower” (don’t ask me why the file has this format), but there must be a mistake in my .items-file. I only get an empty string.

String inv_acpower	"Inverter AC Power [%s]"  {http = "<[[@Type='AC_Power']/@Value)]"}

When I apply this code to some online testing tools (e.g. https://www.freeformatter.com/xpath-tester.html), the result of my parsing is “Value=3414.9”

Anyone can help?
The closest topic seems this one, but did not give any more hints.


1 Like

Running this rule returns the Value. Are you sure you installed the XPath transformation service?

rule "Test XPath"
        Item Test_1 received command
    val testXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><Device Name=\"Inverter\" NominalPower=\"5000\" Type=\"Inverter\" Serial=\"XXX\" BusAddress=\"X\" NetBiosName=\"XXX\" IpAddress=\"\" DateTime=\"2018-07-25T19:15:22\"><Measurements><Measurement Value=\"3414.9\" Unit=\"W\" Type=\"AC_Power\"/><Measurement Value=\"1140.4\" Unit=\"W\" Type=\"AC_Power1\"/><Measurement Value=\"1140.2\" Unit=\"W\" Type=\"AC_Power2\"/><Measurement Value=\"1136.5\" Unit=\"W\" Type=\"AC_Power3\"/><Measurement Value=\"49.989\" Unit=\"Hz\" Type=\"AC_Frequency1\"/><Measurement Value=\"49.998\" Unit=\"Hz\" Type=\"AC_Frequency2\"/><Measurement Value=\"49.998\" Unit=\"Hz\" Type=\"AC_Frequency3\"/><Measurement Value=\"49.9\" Unit=\"°C\" Type=\"Temp\"/><Measurement Value=\"4409.3\" Unit=\"W\" Type=\"GridPower\"/><Measurement Value=\"100.0\" Unit=\"%\" Type=\"Derating\"/></Measurements></Device></root>"
    val mytest = transform("XPATH","/root/Device/Measurements/Measurement[@Type='AC_Power']/@Value" , testXML)
    logInfo("XML Test","Result:" + mytest)

Adapting your rule works fine! Thank you very much!

rule "Test XPath"
        Item inv_acpower received update
    val testXML = inv_acpower.state.toString
    val mytest = transform("XPATH","/root/Device/Measurements/Measurement[@Type='AC_Power']/@Value" , testXML)
    logInfo("XML Test","Result:" + mytest)


[ipse.smarthome.model.script.XML Test] - Result:1873.3

Does this mean, I can only use this XPath-tranfsormation within a rule? :thinking:


I don’t think so. Do you see anythink related to this transformaiton in the logs?

Maybe setting the logging level of the http binding to TRACE gives some hints.