Reading an XML file from an URL - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Reading an XML file from an URL (/showthread.php?tid=85661)
Reading an XML file from an URL by x2i on 08-30-2008 at 01:03 AM
Hi, I was just wondering if there was a way in which to read an XML file from an URL and have it parsed into named variables using Messenger Plus Script.
Put simply, If the XML file given in the url consists of the following data:
<Family>
<Member>
<Name>Peter</Name>
<Age>50</Age>
</Member>
<Member>
<Name>Louis</Name>
<Age>48</Age>
</Member>
</Family>
I would like to parse it so that in the script I could simply call for say Peter's Age and use it in my script. Preferably I would like to parse the data into named variables similar to how VB.NET has the dictionary type array system but any way that works will be good enough.
I have achieved something similar using Visual Basic.NET 2005 and can provide code for that if anyone wants a more in-depth look at what I'm trying to achieve.
If anyone can help or point me in the right direction that would be greatly appreciated - I have a feeling I can create something great if I were able to achieve this.
RE: Reading an XML file from an URL by roflmao456 on 08-30-2008 at 01:30 AM
easy. just simply use the XMLHTTP object
code: var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET","http://url.com/xml.xml",false);
xmlhttp.send(null);
var xml = xmlhttp.responseXML;
var Peter = xml.selectNodes("/Family/Member/Age/text()");
/*
either
var Peter = xml.selectNodes("/Family/Member/Age/text()");
or
var Peter = xml.selectNodes("/Family/Member/Age/text()")[0];
.. haven't used this function much
*/
RE: RE: Reading an XML file from an URL by x2i on 08-30-2008 at 01:52 AM
quote: Originally posted by roflmao456
easy. just simply use the XMLHTTP object
code: var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET","http://url.com/xml.xml",false);
xmlhttp.send(null);
var xml = xmlhttp.responseXML;
var Peter = xml.selectNodes("/Family/Member/Age/text()");
/*
either
var Peter = xml.selectNodes("/Family/Member/Age/text()");
or
var Peter = xml.selectNodes("/Family/Member/Age/text()")[0];
.. haven't used this function much
*/
Hmm this seems to look like it should work, however when I try to return the result I just get 4 squares as a string
EDIT:
I have figured it out by using a javascript example
I used the following:
code: var x = xml.getElementsByTagName("Age")[0];
var Peter = x.childNodes[0];
msgbox(Peter.nodeValue);
Thankyou for your help
|