Shoutbox

XML from internet - 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: XML from internet (/showthread.php?tid=87239)

XML from internet by ArkaneArkade on 11-12-2008 at 06:22 PM

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
RE: XML from internet by matty on 11-12-2008 at 06:35 PM

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;


RE: XML from internet by ArkaneArkade on 11-12-2008 at 07:03 PM

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


RE: XML from internet by SmokingCookie on 11-24-2008 at 07:35 AM

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>)
RE: RE: XML from internet by ArkaneArkade on 11-24-2008 at 08:41 AM

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
RE: XML from internet by SmokingCookie on 11-24-2008 at 11:38 AM

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();
RE: XML from internet by ArkaneArkade on 11-26-2008 at 07:41 AM

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