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

Reading a data file
Author: Message:
wiseguyxp
New Member
*


Posts: 8
Joined: Dec 2009
O.P. Reading a data file
I have some data on my local computer that I would like to "import", if you will, into a script.  I would like to use XML if possible.  The data will influence how commands are executed.  How would I go about reading the data in from the file with a script?
12-11-2009 10:31 AM
Profile E-Mail PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
35 / Male / Flag
Joined: Mar 2003
RE: Reading a data file
There are several ways.

Ini to Object or XML Enumeration

You have to remember the script is JScript with some more advanced functions, so you can use all the normale JScript features in your scripts.

JScript MSDN Documentation
[Image: 1-0.png]
             
12-11-2009 11:46 AM
Profile PM Web Find Quote Report
wiseguyxp
New Member
*


Posts: 8
Joined: Dec 2009
O.P. RE: Reading a data file
I am trying to do XML enumeration and have run into an error that I can't seem to fix.  When I try to shove "Blah" from the XML into the playerName variable, I keep getting "Error: Object required".  I have posted the relevant sections of code below.

Also, I'm not even sure if the script is loading the file correctly.  Is there a way that I can tell if it loaded?

XML:
code:
<root>
<player>
    <name>Blah</name>
</player>
</root>

JScript:
code:
function loadXML(fileName) {
// Create the XML object
var XML = new ActiveXObject ('MSXML.DOMDocument') ;
XML.async = false;
XML.load(fileName);

var playerName = XML.selectSingleNode('/player/name').nodeValue;
}
12-12-2009 07:16 AM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
37 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Reading a data file
Javascript code:
function loadXML(fileName) {
    // Create the XML object
    var XML = new ActiveXObject ('MSXML.DOMDocument') ;
    XML.async = false;
    XML.load(fileName);
 
    var playerName = XML.selectSingleNode('//root/player/name').text;
}

12-12-2009 04:23 PM
Profile E-Mail PM Find Quote Report
wiseguyxp
New Member
*


Posts: 8
Joined: Dec 2009
O.P. RE: Reading a data file
It is still giving me the same error message.  What is the root directory that mplus uses for scripts?  I want to make sure that I'm specifying the correct directory structure when I load the file.  Is there a way to check if a file exists?
12-12-2009 08:38 PM
Profile E-Mail PM Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
36 / Male / Flag
Joined: Nov 2004
Status: Away
RE: Reading a data file
There is no default folder location that a script uses, but there is a value that can be used which gives the path to the scripts folder. I would recommend using this, and adding a folder to keep your XML settings files in.

In short for your function above, you need to specify a full path.
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
12-12-2009 10:01 PM
Profile PM Web Find Quote Report
wiseguyxp
New Member
*


Posts: 8
Joined: Dec 2009
O.P. RE: Reading a data file
Is it sort of like an environment variable?  What is the variable name?
12-13-2009 12:04 AM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
37 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Reading a data file
No its not set up like that. To specify a path you need to use MsgPlus.ScriptFilesPath. It would help us out if you showed us all of your code not just those few lines.

This post was edited on 12-13-2009 at 02:11 AM by matty.
12-13-2009 02:11 AM
Profile E-Mail PM Find Quote Report
wiseguyxp
New Member
*


Posts: 8
Joined: Dec 2009
O.P. RE: Reading a data file
I got the XML reading working.  I used Debug.Trace to print out the path it was using and it was incorrect, so I changed it until it worked.

This post was edited on 12-13-2009 at 11:23 PM by wiseguyxp.
12-13-2009 05:02 AM
Profile E-Mail PM 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