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

XMLDOM
Author: Message:
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
39 / Male / Flag
Joined: Mar 2007
O.P. XMLDOM
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
[Image: adsig.jpg]
10-25-2008 05:32 AM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: XMLDOM
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. :)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
10-25-2008 09:08 AM
Profile E-Mail PM Web Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
39 / Male / Flag
Joined: Mar 2007
O.P. RE: XMLDOM
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

This post was edited on 10-25-2008 at 11:56 PM by ArkaneArkade.
[Image: adsig.jpg]
10-25-2008 03:52 PM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: XMLDOM
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" ?>
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
10-25-2008 06:07 PM
Profile E-Mail PM Web Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
39 / Male / Flag
Joined: Mar 2007
O.P. RE: XMLDOM
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
[Image: adsig.jpg]
10-26-2008 12:06 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