Read the statement by Michael Teeuw here.
Help needed - getting informations from XML File
-
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 useJSON.stringify(xml)
instead ofJSON.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 ofJSON.stringify(xml)
.Does anybody has useful tipps for me?
I am looking forward to your answers.
Best regards
AxLED
-
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
-
@Charley
Thanks for your reply and your code inxml2json.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