Parsing XML Data from Website

  • Platform information:

    • OS:WINDOWS 8
    • openHAB version: 2
  • Issue of the topic: Trying to retrieve XML Data from this site http://ieso.ca/en/Power-Data and not getting anything, also dont seem to see the item created in the panel.

The XML is here http://ieso.ca/-/media/files/ieso/uploaded/chart/price_multiday.xml?la=en

XPATH that im using that seems to work on the tester - /Root/DataSet/Data/Value/number()
.Rules

rule "Convert XML to Item Type Number"
  when
    Item Price_xml changed
  then
    // use the transformation service to retrieve the value
    // Simple
    val mytest = transform("XPATH", "/*[name()='Root']				
                                     /*[name()='DataSet']
                                     /*[name()='Data']
									 /*[name()='Value']
                                     /text()", 
                                    Price_xml.state.toString )  
    // Fully qualified
    val mytest = transform("XPATH", "/*[local-name()='Root'    and namespace-uri()='http://www.w3.org/2001/XMLSchema-instance']
                                     /*[local-name()='DataSet' and namespace-uri()='http://www.w3.org/2001/XMLSchema-instance']
                                     /*[local-name()='Data'      and namespace-uri()='http://www.w3.org/2001/XMLSchema-instance']
                                     /*[local-name()='Value'      and namespace-uri()='http://www.w3.org/2001/XMLSchema-instance']
									 /text()",
                                    Price_xml.state.toString )

    // post the new value to the Number Item
    Price.postUpdate( newValue )
end

.item

//XPATH /Root/DataSet/Data/Value/number() TESTED ON WEBSITE
String  Price_xml "Price [XPATH(/*[name()='Root']/*[name()=DataSet']/*[name()='Data']/*[name()=Value']/):%s $]" {...}
Number  Price "Price [%.1f $]"

EDIT: I have updated some of the obvious errors i have made with the code, as i had the XPATH expression totally messed up.

If i can get any input on what i might be doing wrong, it will be greatly appreciated.
Thanks guy!

Maybe I don’t understand it, but where do you get the XML from the website?

Sorry, I meant how the XML is stored in the Price_xml item? I don’t see a http action or the usage of the http binding.

.http

Price_xml.url=http://www.w3.org/2001/XMLSchema-instance
Price_xml.updateInterval=60000

Ok, I think you get some things wrong.

  1. your file should be named like http.cfg. Is it in the services directory?
  2. Inside the http.cfg you should have that:
    Price_xml.url=http://ieso.ca/-/media/files/ieso/uploaded/chart/price_multiday.xml?la=en
  3. Your item must reference the configuration:
http="<[Price_xml:60000:<transformationrule>]"

But I don’t know if you can get the while XML using that way. I’m using the http action an a role with a cron job.

Yes, i have that inside the http.cfg file.

The newValue attribute doesn’t exist.