What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Reading an XML file from an URL

Reading an XML file from an URL
Author: Message:
x2i
New Member
*

Avatar

Posts: 2
Joined: Aug 2008
O.P. Reading an XML file from an URL
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.
08-30-2008 01:03 AM
Profile E-Mail PM Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: Reading an XML file from an URL
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 :p
*/


This post was edited on 08-30-2008 at 01:30 AM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
08-30-2008 01:30 AM
Profile PM Web Find Quote Report
x2i
New Member
*

Avatar

Posts: 2
Joined: Aug 2008
O.P. RE: RE: Reading an XML file from an URL
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 :p
*/



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 :S

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 :D

This post was edited on 08-30-2008 at 02:05 AM by x2i.
08-30-2008 01:52 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On