What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » XML Reading/Parsing

XML Reading/Parsing
Author: Message:
Paril
Junior Member
**

Avatar
Admin of Paril's Projects

Posts: 69
30 / Male / Flag
Joined: Jul 2006
O.P. XML Reading/Parsing
Hey there.

I'm attempting to grab an XML Feed from a stat page, record it's information and display certain parts of it. Is there any example code around for dealing with XML documents?

-Paril
05-18-2008 01:48 PM
Profile E-Mail PM Web Find Quote Report
mynetx
Skinning Contest Winner
*****

Avatar
Microsoft insider

Posts: 1175
Reputation: 33
36 / Male / Flag
Joined: Jul 2007
RE: XML Reading/Parsing
Hello Paril,

first of all, your avatar URL is outdated: http://www.royalorigins.net/Portrait_Cloud.gif
Then, fetch the Official Scripting Documentation. It might help you.
Third, load the XML contents from its location. You can use the normal COM objects Microsoft.XMLHTTP and Microsoft.XMLDOM for it. Simply use
var objXml = new ActiveXObject("Microsoft.XMLDOM");
You will find more information about Microsoft.XMLDOM and its properties within the Microsoft Developers Network (MSDN) at http://msdn.microsoft.com/en-us/library/aa468547.aspx.
Regards,
mynetx - Microsoft, enhanced.

You have a problem or issue with Windows, Internet
Explorer or Office?
Send a tweet!
05-18-2008 02:01 PM
Profile E-Mail PM Web Find Quote Report
Paril
Junior Member
**

Avatar
Admin of Paril's Projects

Posts: 69
30 / Male / Flag
Joined: Jul 2006
O.P. RE: XML Reading/Parsing
Thanks, site must be down. Oh well. Nothing big. Haven't been here in a while.

I had checked through there, not much that I saw that helped much.

I'll take a look, thanks.

-Paril
05-18-2008 02:04 PM
Profile E-Mail PM Web Find Quote Report
Paril
Junior Member
**

Avatar
Admin of Paril's Projects

Posts: 69
30 / Male / Flag
Joined: Jul 2006
O.P. RE: XML Reading/Parsing
I tried this just to test it:

code:
function OnEvent_Initialize(MessengerStart)
{
    var objXml = new ActiveXObject("Microsoft.XMLDOM");
   
    if (objXml.Load ("http://stats.enemyterritory.com/profile/paril101?xml=true"))
    {
        Debug.Trace("Made it!\n");
    }
    else
    {
    }
}

However I got an error on it.. Is there any example code lying around of an entire one used in MsgPlus? I'm not exactly sure how I'm supposed to.. interpret this code from (what looks like) VB.

-Paril

This post was edited on 05-18-2008 at 02:17 PM by Paril.
05-18-2008 02:17 PM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: XML Reading/Parsing
MeEtc wrote a nice tutorial how to do this: [Tutorial] Communicating with web pages. Take a look at the section "Retrieving content of a web page" before you continue. It's really worth to read it! :)

The only difference is that you can use the xmlhttp.responseXML property rather than xmlhttp.responseText, as this contains a nice XMLDOM object, ready for you to edit!

Here you have an example on what you can do with it:
code:
var url = "http://stats.enemyterritory.com/profile/paril101?xml=true";
   
Interop.Call("wininet.dll", "DeleteUrlCacheEntryW", url);
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function () {
   if (xmlhttp.readyState == 4) {
      if (xmlhttp.status == 200) {
         // Data from URL was retrieved successfully
         // You can now use xmlhttp.responseXML
         var xml = xmlhttp.responseXML;
         Debug.Trace("Engineer XP:"+xml.selectSingleNode("player/xp/engineer").getAttribute("xp"));
      } else {
         // The server returned an HTTP code other than 200
         Debug.Trace("ERROR!");
      }
   }
}
xmlhttp.send();
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
05-18-2008 04:46 PM
Profile E-Mail PM Web Find Quote Report
Paril
Junior Member
**

Avatar
Admin of Paril's Projects

Posts: 69
30 / Male / Flag
Joined: Jul 2006
O.P. RE: XML Reading/Parsing
Ahh, that's perfect. Thanks. My uber-ness can take over from here. :p

-Paril
05-18-2008 09:59 PM
Profile E-Mail PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1621
Reputation: 50
35 / Male / Flag
Joined: Jan 2006
RE: XML Reading/Parsing
For a wiki with what xml stuff you can do with that object I use http://www.devguru.com/technologies/xmldom/quickr...mldom_objects.html

It also gives some vb and/or jscript examples with most of the properties or methods
[Image: markee.png]
05-18-2008 10:40 PM
Profile PM Find Quote Report
Paril
Junior Member
**

Avatar
Admin of Paril's Projects

Posts: 69
30 / Male / Flag
Joined: Jul 2006
O.P. RE: XML Reading/Parsing
Okay, thanks.

Another question.. the ET:QW stats page also have some XML objects that are named the same, ie:
code:
<badges category="soldier" level="1">
<tasks total="600" id="1" value="8768.6899802"/>
<tasks total="2" id="2" value="87"/>
</badges>
<badges category="soldier" level="2">
<tasks total="3000" id="1" value="8768.6899802"/>
<tasks total="2000" id="2" value="2617.059387822"/>
<tasks total="20" id="3" value="87"/>
</badges>

How would I distinguish these apart, like getting the "total" under level "1" category "soldier" of task id "1"?

-Paril

This post was edited on 05-19-2008 at 12:15 AM by Paril.
05-19-2008 12:14 AM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: XML Reading/Parsing
You can easily do that by using the right statements in your search parameter for xml.selectSingleNode():
code:
var node = xml.selectSingleNode("badges[@category='soldier'][@level='1']/tasks[@id='1']");
var total = node.getAttribute("total");
The parts in green are selectors for attributes, this means that the XMLDOM engine will first look for a node with the name 'badges' and then will check if it's category-attribute equals 'soldier' and the level is '1'. If this is true, it'll look in its child nodes for 'tasks'-nodes and if it finds one with id '1', it'll return that node. Then, you can simply use the Node.getAttribute("attribute_name") method to get the 'total' attribute from the node. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
05-19-2008 03:36 PM
Profile E-Mail PM Web Find Quote Report
Paril
Junior Member
**

Avatar
Admin of Paril's Projects

Posts: 69
30 / Male / Flag
Joined: Jul 2006
O.P. RE: XML Reading/Parsing
Oh, cool, this is much simpler than the code Josh gave me.. thanks

-Paril
05-20-2008 01:26 PM
Profile E-Mail PM Web 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