Shoutbox

Load XML - 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: Load XML (/showthread.php?tid=77342)

Load XML by SnuZZer on 09-09-2007 at 04:50 PM

Hi.
I'm trying to get information from a XML document, but my script doesn't work.
Here is my code:

code:
36: var xml = new ActiveXObject( "Microsoft.XMLDOM" );
37:
38: var xmlOpdaterFil = MsgPlus.ScriptFilesPath + "\\kanal.xml";
39: xml.load(xmlOpdaterFil);
40:     
41: var hentKanal = xml.selectNodes("/Item/Kanal");
42:
43: kanal = hentKanal[1].text;

I have tried to translate the error from danish to english:
code:
Function called: OnEvent_Uninitialize
The script is stopped
The script is starting
The script is started and ready
Function called: OnEvent_Initialize
Error: An object is obligatory (code: -2146827864)
       File: TV Guide.js. Line: 43.
Function OnEvent_Initialize gave an error. Code: -2147352567

Anyone who knows why it doesn't work?

Thanks in advance.
RE: Load XML by NanaFreak on 09-09-2007 at 08:44 PM

code:
43: kanal = xml.hentKanal[1].text;

maybe that?
RE: Load XML by ShawnZ on 09-09-2007 at 09:29 PM

quote:
Originally posted by NanaFreak
code:
43: kanal = xml.hentKanal[1].text;

maybe that?

41: var hentKanal = xml.selectNodes("/Item/Kanal");
42:
43: kanal = hentKanal[1].text;
RE: Load XML by deAd on 09-09-2007 at 09:43 PM

It looks like the selectNodes call isn't returning any nodes.


RE: Load XML by matty on 09-10-2007 at 12:01 AM

Select Nodes returns an Array of the nodes.

code:
36: var xml = new ActiveXObject( "Microsoft.XMLDOM" );
37:
38: var xmlOpdaterFil = MsgPlus.ScriptFilesPath + "\\kanal.xml";
39: xml.load(xmlOpdaterFil);
40:
41: var hentKanal = xml.selectNodes("/Item/Kanal");
42:
43: for (var i=0; i<hentKanal.length; i++) {
44:     Debug.Trace(hentKanal[i]);
45: }

RE: Load XML by SnuZZer on 09-10-2007 at 04:37 AM

When I use the code Matty have posted it says:

code:
Function called: OnEvent_Uninitialize
Script has been stopped
Script is starting
Script is now loaded and ready
Function called: OnEvent_Initialize
Error: Types doesn't match (code: -2146828275)
       File: TV Guide.js. Line: 45.
Function OnEvent_Initialize returned an error. Code: -2147352567

But actually it's only one thing in the XML, I need, I just thought it was easier to make it as an array and then choose number one in the array, but it must be possible just to choose one "node"?

This is my XML:
code:
<?xml version="1.0" encoding="UTF-16"?>
<Item>
    <Kanal>1</Kanal>
</Item>

RE: Load XML by -dt- on 09-10-2007 at 04:41 AM

quote:
Originally posted by SnuZZer
But actually it's only one thing in the XML, I need, I just thought it was easier to make it as an array and then choose number one in the array, but it must be possible just to choose one "node"?
Arrays are 0 based so they start at 0, not 1, so 1 really = 2 in the array index
RE: Load XML by SnuZZer on 09-10-2007 at 01:16 PM

Hi.
Oh, thanks -dt-!
It's so embarrassing I forgot that!

So, here is the final script:

code:
    var xmlOpdaterFil = MsgPlus.ScriptFilesPath + "\\kanal.xml";
    xml.load(xmlOpdaterFil);

    var xml = new ActiveXObject( "Microsoft.XMLDOM" );

    var xmlOpdaterFil = MsgPlus.ScriptFilesPath + "\\kanal.xml";
    xml.load(xmlOpdaterFil);

    var hentKanal = xml.selectNodes("/Item/Kanal");

    kanal = hentKanal[0].text;

Thanks to everybody for helping! (L)