Save to 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: Save to XML (/showthread.php?tid=67840)
Save to XML by SnuZZer on 10-29-2006 at 04:16 PM
Hi.
I'm from Denmark and my english isn't good, but i'll try and hope that you undertand
I try to make a script which can auto-answer message, with a message the user have choosed, but i can't find out how to save the users settings in a XML-document as i later can get the settings again and use them.
I save the users settings in a variable here and now I will put the settings into a XML-document:
code: function OnWndMainEvent_CtrlClicked(Wnd, Handling)
{
switch(Handling)
{
case "knap_tilfoej":
var Navn = Wnd.GetControlText("input_navn");
var Modtaget = Wnd.GetControlText("input_modtaget");
var Svar = Wnd.GetControlText("input_svar");
break;
case "knap_luk":
Wnd.Close(1);
break;
}
}
Thanks in advance
Simon
RE: Save to XML by Felu on 10-29-2006 at 04:23 PM
[Help!] Writing to XML files
RE: Save to XML by SnuZZer on 10-29-2006 at 04:36 PM
Hi.
When i click on "knap_tilfoej" and try to save the settings nothing happens. It doesn't close the window and it doesn't save the settings.
Here is the script:
code: function OnWndMainEvent_CtrlClicked(Wnd, Handling)
{
switch(Handling)
{
case "knap_tilfoej":
var Navn = Wnd.GetControlText("input_navn");
var Modtaget = Wnd.GetControlText("input_modtaget");
var Svar = Wnd.GetControlText("input_svar");
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.load("indstillinger.xml");
var toAdd = xml.createElement("Navn");
toAdd.appendChild(xml.createTextNode(Navn));
xml.getElementsByTagName("Navn")[0].appendChild(toAdd);
xml.save("indstillinger.xml");
break;
case "knap_luk":
Wnd.Close(1);
break;
}
}
RE: Save to XML by Plan-1130 on 10-29-2006 at 07:47 PM
xml.load("indstillinger.xml");
xml.save("indstillinger.xml");
I guess you need to insert the full path, like
MsgPlus.ScripFilesPath + "\\indstillinger.xml"
RE: Save to XML by Spunky on 10-29-2006 at 09:44 PM
unlikely... It should use a file in the local folder...
RE: Save to XML by deAd on 10-29-2006 at 10:48 PM
quote: Originally posted by SnuZZer
Hi.
When i click on "knap_tilfoej" and try to save the settings nothing happens. It doesn't close the window and it doesn't save the settings.
Here is the script:
The window will not close unless you click on "knap_luk", which you didn't.
Also, try using full paths in the xml.load and xml.save.
Is there anything in the debug window when you do this?
RE: Save to XML by Plan-1130 on 10-30-2006 at 01:09 PM
quote: Originally posted by SpunkyLoveMuff
unlikely... It should use a file in the local folder...
Which is the My Documents folder and i found that very unlikely to put an XML file...
Btw, if you want to close the window after saving the file (when it works) remove break;
code: function OnWndMainEvent_CtrlClicked(Wnd, Handling)
{
switch(Handling)
{
case "knap_tilfoej":
var Navn = Wnd.GetControlText("input_navn");
var Modtaget = Wnd.GetControlText("input_modtaget");
var Svar = Wnd.GetControlText("input_svar");
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.load("indstillinger.xml");
var toAdd = xml.createElement("Navn");
toAdd.appendChild(xml.createTextNode(Navn));
xml.getElementsByTagName("Navn")[0].appendChild(toAdd);
xml.save("indstillinger.xml");
// Removed the break; here
case "knap_luk":
Wnd.Close(1);
break;
}
}
RE: Save to XML by SnuZZer on 10-30-2006 at 02:31 PM
Hi.
Now I have tried with MsgPlus.ScripFilesPath + "\\indstillinger.xml" but I can't get it work.
Heres my code:
code: function OnWndMainEvent_CtrlClicked(Wnd, Handling)
{
switch(Handling)
{
case "knap_tilfoej":
var Sti = MsgPlus.ScriptFilesPath + "\\indstillinger.xml";
var Navn = Wnd.GetControlText("input_navn");
var Modtaget = Wnd.GetControlText("input_modtaget");
var Svar = Wnd.GetControlText("input_svar");
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.load(Sti);
var toAdd = xml.createElement("Navn");
toAdd.appendChild(xml.createTextNode(Navn));
xml.getElementsByTagName("Navn")[0].appendChild(toAdd);
xml.save(Sti);
Wnd.Close(1);
break;
case "knap_luk":
Wnd.Close(1);
break;
}
}
And here is my XML-document (indstillinger.xml)
code: <?xml version="1.0" encoding="UTF-8"?>
<Indstillinger>
</Indstillinger>
RE: Save to XML by Matti on 10-30-2006 at 03:10 PM
Can you please tell us what the debugger says? It gives important information about the error!
RE: Save to XML by SnuZZer on 10-30-2006 at 04:49 PM
Hi.
When i open a script the debugger doesn't popup, isn't that the meaning?
I have checked the checkbox.
RE: Save to XML by Matti on 10-30-2006 at 04:54 PM
You have 2 ways to open the debugger:
- In the contact list, open the Plus! menu (note: not the Plus! icon menu, but the one next to the Help menu) and select Script Debugging Window. Select your script in the list and look what the textbox says.
- In your script, add this to your OnEvent_Initialize function:
code: Debug.DebuggingWindowVisible = true;
to open the window whenever you start the script. Don't forget to remove it when you're planning to release it! When you've done that, start your script and see if it gives you an error message.
RE: Save to XML by SnuZZer on 10-30-2006 at 05:01 PM
Hi.
The debugger says this:
Scriptet er blevet stoppet
Scriptet startes
Scriptet er startet og er klar
Funktion kaldt: OnGetScriptMenu
Funktion kaldt: OnEvent_MenuClicked
Funktion kaldt: OnWndMainEvent_CtrlClicked
Fejl: 'getElementsByTagName(...).0' er null eller ikke et objekt.
Linje: 50. Kode: -2146823281.
Funktion OnWndMainEvent_CtrlClicked gav en fejl. Kode: -2147352567
Funktion kaldt: OnWndMainEvent_CtrlClicked
I have tried to translate to english:
The scriptet has been stopped
The script is starting
The script is started and are ready
Function called: OnGetScriptMenu
Function called: OnEvent_MenuClicked
Function called: OnWndMainEvent_CtrlClicked
Error: 'getElementsByTagName(...).0' is null or isn't a object.
Line: 50. Code: -2146823281.
Function OnWndMainEvent_CtrlClicked gave an error. Code: -2147352567
Function called: OnWndMainEvent_CtrlClicked
RE: Save to XML by SnuZZer on 10-30-2006 at 07:04 PM
Hi.
Now it works!
I have written "Navn" instead of "Indstillinger".
code: function OnWndMainEvent_CtrlClicked(Wnd, Handling)
{
switch(Handling)
{
case "knap_tilfoej":
var Sti = MsgPlus.ScriptFilesPath + "\\indstillinger.xml";
var Navn = Wnd.GetControlText("input_navn");
var Modtaget = Wnd.GetControlText("input_modtaget");
var Svar = Wnd.GetControlText("input_svar");
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.load(Sti);
var toAdd = xml.createElement("Navn");
toAdd.appendChild(xml.createTextNode(Navn));
xml.getElementsByTagName("Indstillinger")[0].appendChild(toAdd);
xml.save(Sti);
Wnd.Close(1);
break;
case "knap_luk":
Wnd.Close(1);
break;
}
}
But I still got a problem
How can I add more to the XML-document in one? So - I got more information to add, and how can i give it a ID?
Like this:
code: <?xml version="1.0" encoding="UTF-8"?>
<Indstillinger>
<Navn Id="Test">
<Modtaget>Hej</Modtaget>
<Svar>Hey!</Modtaget>
</Navn>
<Navn Id="Trala">
<Modtaget>Yeah!</Modtaget>
<Svar>Yeees!!</Modtaget>
</Navn>
</Indstillinger>
RE: Save to XML by Spunky on 10-30-2006 at 08:38 PM
quote: Originally posted by Plan-1130
Which is the My Documents folder and i found that very unlikely to put an XML file...
Erm, no... The MsgPlus.ScriptFilesPath is the local folder. You can only write a file to "My Documents" using a full path
|