Page 1 of 1

Writing text to an XML file

Posted: Thu Feb 02, 2012 4:39 pm
by bobtimpone
Hi All
This place is becoming a home away from home for me :}
I have a user form with about 13 different user input fields.
I call them text 1-13 I would like to write them out to an XML file named by the date and time.
Can you point me in the right direction ?
Bob

Re: Writing text to an XML file

Posted: Thu Feb 02, 2012 6:37 pm
by mwieder
Writing to a text file is pretty easy. There are (at least) two different ways:

Code: Select all

ask file -- see where the user wants to store the file
if it is not empty then
  put tText into url ("file:" & tPath)
end if

Code: Select all

ask file -- see where the user wants to store the file
if it is not empty then
  open file tPath
  write tText to file tPath
  close file tPath
end if
For generating xml I usually don't bother with the built-in xml routines - it's easier to do this myself:

Code: Select all

function xmlTag pTag, pText
local tXML

  put "<" & pTag & ">" into tXML
  put pText after tXML
  put "</" & pTag & ">" after tXML
  return tXML
end xmlTag
and, of course, you can get fancier with CDATA stuff or whatever as needed. Just gather all the xml into a variable, then put it into a text file and you're done.