Writing text to an XML file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bobtimpone
Posts: 25
Joined: Tue Jan 03, 2012 9:10 pm

Writing text to an XML file

Post by bobtimpone » Thu Feb 02, 2012 4:39 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Writing text to an XML file

Post by mwieder » Thu Feb 02, 2012 6:37 pm

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.

Post Reply