MagicMirror² v2.14.0 is available! For more information about this release, check out this topic.

Help needed - getting informations from XML File

  • Module Developer

    Hi to the java gurus,

    i am having troubel to get to the right informations of an XML File.
    I try to read a xml file of a TV set top box (Dreambox, Linux OS, Enigma2).
    The xml file is provided by the webservice of the box in the same LAN (see sample below).
    I already got following working reading the xml file into a variable (in node_helper.js) and sending this to the module.js.
    I have to use JSON.stringify(xml) instead of JSON.parse(xml) otherwise i got an error of some special charachters found in xml.

    Sample of XML

    <?xml version="1.0" encoding="UTF-8"?>
    		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "" ORDER BY bouquet</e2servicereference>
    		<e2servicename>Favourites (TV)</e2servicename>
    				<e2servicename>Das Erste HD</e2servicename>
    				<e2servicename>ZDF HD</e2servicename>

    If i send the content of xml to console.log it shows me the right content, but the whole xml file.

    Now i want to get only some datas out of the xml file, but the following didnt work:

    this.reference = xml.e2servicereference;
    this.e2servicelist = xml.e2servicelist;
    this.reference = xml.e2servicereference[0];
    this.e2servicelist = xml.e2servicelist[0];

    I get an error that xml.whateveritrytoectract is undefined.

    I tried to use code samples of MMM-RNV which unfortuantelly didnt work, but he is using JSON.parse(xml) instead of JSON.stringify(xml).

    Does anybody has useful tipps for me?

    I am looking forward to your answers.

    Best regards


  • Module Developer

    The easiest I have used is to conevrt to json
    just add xml2json like I have used in my Bose Soundtouch module.

    This is the link to the js file


    var json=xml2json(data);

    can use the variables quickly.

    Good luck

  • Module Developer

    Thanks for your reply and your code in xml2json.js.
    Now i can get the requested values of my xml and can move forward in developing.

    If somebody knows a way to directly extract datas of xml could be an optimization afterwards, to reduce code.



Log in to reply