MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Help needed - getting informations from XML File

    Scheduled Pinned Locked Moved Development
    3 Posts 2 Posters 1.2k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      AxLed Module Developer
      last edited by AxLed

      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"?>
      <e2servicelistrecursive>
      	<e2bouquet>
      		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet</e2servicereference>
      		<e2servicename>Favourites (TV)</e2servicename>
      		<e2servicelist>
      			<e2service>
      				<e2servicereference>1:0:19:2B5C:41B:1:FFFF014A:0:0:0:</e2servicereference>
      				<e2servicename>Das Erste HD</e2servicename>
      			</e2service>
      			<e2service>
      				<e2servicereference>1:0:19:2B66:437:1:FFFF01C2:0:0:0:</e2servicereference>
      				<e2servicename>ZDF HD</e2servicename>
      			</e2service>
      		</e2servicelist>
      	</e2bouquet>
      </e2servicelistrecursive>
      

      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

      AxLED

      1 Reply Last reply Reply Quote 0
      • C Offline
        Charley Module Developer
        last edited by

        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

        with

        var json=xml2json(data);
        
        

        can use the variables quickly.

        Good luck

        MMM-Bose-Soundtouch, MMM-Domoticz, MMM-crypto-portfolio, MMM-Fibaro, MMM-rain-forecast

        1 Reply Last reply Reply Quote 0
        • A Offline
          AxLed Module Developer
          last edited by

          @Charley
          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.

          Regards

          AxLED

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Sam, technical setup by Karsten.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy