What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help!] Writing to XML files

[Help!] Writing to XML files
Author: Message:
rob_botch
Full Member
***

Avatar

Posts: 180
Reputation: 4
33 / Male / Flag
Joined: Apr 2006
O.P. [Help!] Writing to XML files
I want to write a script which has one part of its function to log certain messages to an xml file. Each time the script is run, it will add a few tags. for example, <Message>...</Message> for each message. Of course, it will have to have tags around the whole file, such as <Messages>...</Messages>. My query is this: How would I discard the last line of the saved file before writing the new tags? The closing tag would then be added back on.

Thank you,
07-05-2006 11:25 AM
Profile E-Mail PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
35 / Male / Flag
Joined: Mar 2004
RE: [Help!] Writing to XML files
err why not use the XML com object?

code:
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.load("filename of xml here");

//create the element to be added
var toAdd = xml.createElement("test");

//add a message to it
toAdd.appendChild(xml.createTextNode("testing this"));


//add it into our xml
xml.getElementsByTagName("Messages")[0].appendChild(toAdd);


//save our xml
xml.save("filename of xml here");

[Image: dt2.0v2.png]      Happy Birthday, WDZ
07-05-2006 11:56 AM
Profile PM Web Find Quote Report
rob_botch
Full Member
***

Avatar

Posts: 180
Reputation: 4
33 / Male / Flag
Joined: Apr 2006
O.P. RE: [Help!] Writing to XML files
Thank you for your help.

How would I add more than one child to a parent tag at once. For example, to add the following to an XML file for every message received:

<Message>
          <Sender>Test</Sender>
          <Text>Test Text</Text>
</Message>

Hope you can help,

Edit: I've managed to do this, but the children are always added to the same parent, instead of new ones. How would I retrieve the number of <Message> tags in the file?

This post was edited on 07-05-2006 at 01:01 PM by rob_botch.
07-05-2006 12:52 PM
Profile E-Mail PM Web Find Quote Report
mathieumg
Full Member
***


Posts: 181
Reputation: 2
34 / Male / Flag
Joined: May 2004
RE: [Help!] Writing to XML files
code:
var IntMessagesLen = xml.getElementsByTagName("Messages").length; //How many <Message></Message> pairs
xml.getElementsByTagName("Messages")[IntMessagesLen - 1]; //This will do nothing, but you can append any function you want to do on the object (which is the last <Message></Message> pair contained in the xml file.


Hope this helps :)

This post was edited on 07-05-2006 at 06:51 PM by mathieumg.
Official MessengerPlus! Live French Translator
Official StuffPlug 3 French Translator

:)
07-05-2006 06:50 PM
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