Shoutbox

XMLDOM - 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: XMLDOM (/showthread.php?tid=86860)

XMLDOM by ArkaneArkade on 10-25-2008 at 05:32 AM

Hey folks,
I'm trying to sort a script out, to read data from an XML file (Just read... don't think writing is necessary... at least not yet), but I just keep running into problems with it.
I've searched all over the forums, and read the scripting threads which mention XMLDOM, and then tried to frankenstein each of them to work for me, but to no avail.

The error I'm getting is Error: Object required (code: -2146827864).       File: XML.js. Line: 5.

My code is this

JScript code:
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.load(MsgPlus.ScriptFilesPath + '\\gameinfo.xml');
 
var node = xml.selectNodes("game[@name='FIFA06']/title");
var info = node[0].text;
Debug.Trace(info);


And my xml file is
XML code:
<?xml version="1.0">
<gameslist>
    <game name="FIFA06">
        <title>Road to FIFA World Cup</title>
        <psm>Playing soccer</psm>
    </game>
    <game name="PD">
        <title>Perfect Dark Zero</title>
        <psm>Killing people</psm>
    </game>
</gameslist>

Obviously I intend to add a LOT more to the xml, but thats all I'm using just now.  I have also tried using node.text whcih doesnt give an error, but also gives no text, perhaps just a space.
Can anyone see what I've done wrong, or give me any pointers>
Any help is appreciated
Leroux
RE: XMLDOM by Matti on 10-25-2008 at 09:08 AM

JScript code:
var node = xml.selectNodes("game[@name='FIFA06']/title");

This would assume that the "game" node is at the root of your document, but it isn't. There are a few ways to do this in the correct way:
JScript code:
var node = xml.selectNodes("gameslist/game[@name='FIFA06']/title");
or
var node = xml.selectNodes("//game[@name='FIFA06']/title");
or
var node = xml.selectNodes("/*/game[@name='FIFA06']/title");

Also, because I think that you don't want two game nodes to have the same name attribute, you can simply avoid using selectNodes and use selectSingleNode instead:
JScript code:
var node = xml.selectSingleNode("gameslist/game[@name='FIFA06']/title");
var info = node.text;

Hopefully this works for you. :)
RE: XMLDOM by ArkaneArkade on 10-25-2008 at 03:52 PM

Matti,  cheers for the help, I've changed to use the single node and it's working now.  It didnt at first, and I spent a while stressing, till I reread your reply, and thought of the document level nodes.  I've now removed the <?xml version="1.0"> and it works perfectly.

thanks man
Leroux


RE: XMLDOM by Matti on 10-25-2008 at 06:07 PM

Hmm, that's quite odd. I'd highly recommend you to keep your XML file header. The XML header isn't actually part of the document, it simply tells the parser what it is. Maybe you have to specify the file encoding in the header to make it work properly?

Example:

XML code:
<?xml version="1.0" encoding="UTF-16" ?>


RE: XMLDOM by ArkaneArkade on 10-26-2008 at 12:06 AM

I tried just copying and pasting what you said Matti, but I get back to my same error again.
However, I did find the problem in the original xml.  I'd missed the closing '?' after the xml version.
Perhaps there's something wrong in my encoding?  I do actually have need of a couple of wierd symbols in my text (specifically 'ñ') which breaks the script.  I was gonna write a workaround for it in the script, but perhaps theres a specific encoding which may make it work?

Thanks for the help again dude.
Leroux