Shoutbox

Reading a data file - 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: Reading a data file (/showthread.php?tid=93177)

Reading a data file by wiseguyxp on 12-11-2009 at 10:31 AM

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?


RE: Reading a data file by Ezra on 12-11-2009 at 11:46 AM

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


RE: Reading a data file by wiseguyxp on 12-12-2009 at 07:16 AM

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;
}

RE: Reading a data file by matty on 12-12-2009 at 04:23 PM

js 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;
}

RE: Reading a data file by wiseguyxp on 12-12-2009 at 08:38 PM

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?


RE: Reading a data file by MeEtc on 12-12-2009 at 10:01 PM

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.


RE: Reading a data file by wiseguyxp on 12-13-2009 at 12:04 AM

Is it sort of like an environment variable?  What is the variable name?


RE: Reading a data file by matty on 12-13-2009 at 02:11 AM

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.


RE: Reading a data file by wiseguyxp on 12-13-2009 at 05:02 AM

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.