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

XML from internet
Author: Message:
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
38 / Male / Flag
Joined: Mar 2007
O.P. XML from internet
Hey guys,
I'm looking to improve my script by having the XML online.

I've tryed to write a function, but I can't get it to work and I'm not sure why.
JScript code:
function readwebnode(game, node)
{
    xml.load("http://www.arkanes-arkade.co.uk/x360/x360-db.xml");
 
    xml.onreadystatechange=function()
    {
        if (xml.readyState == 4)
        {
            var value = xml.selectSingleNode("gameslist/game[@name='"+game+"']/"+node).text;
            Debug.Trace(value);
        }
    }
}

I'm calling this at startup just to test, and using readwebnode("Crackdown", "psm"); to call it.  this is one of the first things in the xml, and also since it's only 1 word I figured it would be easier.
When it runs though, I get "Error: Object required (code: -2146827864)" appear twice in the debug window, referring to line 118 (the line beginning var value).
I've tried using almost identical code, without the readystate etc on a local copy of the same file, and it returns properly, so I'm guessing that my problem is to do with the dl, but I don't know enough to see my problem.  can anyone help me out?
Cheers guys
[Image: adsig.jpg]
11-12-2008 06:22 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: XML from internet
You need to preceed gameslist with a / or //.

Therefore
JScript code:
var value = xml.selectSingleNode('/gameslist/game[@name="'+game+'"]/'+node).text;

or
JScript code:
var value = xml.selectSingleNode('//gameslist/game[@name="'+game+'"]/'+node).text;

11-12-2008 06:35 PM
Profile E-Mail PM Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
38 / Male / Flag
Joined: Mar 2007
O.P. RE: XML from internet
OK.  I'm not actually sure why what I pasted is different, but I do already have the gameslist preceded by a double-backslash.  It still gives the same error though. :S
[Image: adsig.jpg]
11-12-2008 07:03 PM
Profile E-Mail PM Web Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: XML from internet
You should not use a backslash (\) as in a file path, but a normal slash (/) as in URLs.

Also, for more interaction with nodes, you may want to use this.

JScript code:
var node = xml.selectSingleNode("/gameslist/game[@name=\"" + game + "\"]/" + node);
var value = node.text;


In this example, you can give the game attributes (like <Tag> <Subtag value="Hello world!" /> </Tag>)

This post was edited on 11-24-2008 at 07:41 AM by SmokingCookie.
11-24-2008 07:35 AM
Profile PM Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
38 / Male / Flag
Joined: Mar 2007
O.P. RE: RE: XML from internet
quote:
Originally posted by SmokingCookie
You should not use a backslash (\) as in a file path, but a normal slash (/) as in URLs.
Lol, feel free to ignore the idiot.  I tend to screw up with my typing a lot - the backward slash I referred to was in fact what normal people refer to as a forward-slash.  I however will not conform to that.  apparently. :S

I'm not sure what you mean by the further interaction though?  You have to remember, I may look intelligent, but it's all an act :P
[Image: adsig.jpg]
11-24-2008 08:41 AM
Profile E-Mail PM Web Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: XML from internet
Hehe :P

Point is, that you may use XML attributes as in the example above, but you'll need to create an object (the "node" thingy in my code), or make several calls to selectSingleNode();

Take a look here:

XML code:
<?xml version="1.0" encoding="Unicode"?> <!-- This is a comment -->
<RootElement attribute="Every element may have attributes"> <!-- the root element is required; only one per doc -->
      <Element attribute="This is an an attribute" /> <!-- self-closing lement (or whatever it's called) with an attribute -->
      <Element>Element text</Element> <!-- this element has no attributes but element text -->
      <Element attribute="Another tattribute">And some text</Element> <!-- This one's got both text and attributes -->
</RootElement> <!-- close RootElement -->


Now, to get text, and only text, you can use your own piece of code. If you want attributes and/or text, you may want to use this:

JScript code:
function getXMLStuff(XMLData) { // An XML string
      var xml = new ActiveXObject("Microsoft.XMLDOM");
      if(xml.loadXML(XMLData)) { // Load the XML string
            var D = xml.selectSingleNode("/RootElement/Element"); // Select the first "Element" tag
            var VAL = D.getAttribute("Attribute"); // This doesn't work
            var Txt = D.text;
      }
}


If you use XMLHTTP to download the XML file from the internet, you'll need either the XMLHTTP's methods to parse the XML, or use XMLDOM.loadXML();

This post was edited on 11-24-2008 at 11:39 AM by SmokingCookie.
11-24-2008 11:38 AM
Profile PM Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
38 / Male / Flag
Joined: Mar 2007
O.P. RE: XML from internet
OK man, I see what you mean now.  However, it is only the text I want from anything... although I'll make sure keep in mind if I'm doing any updates later on :D
[Image: adsig.jpg]
11-26-2008 07:41 AM
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