Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Any way to edit text or XML files?

I see the options that allow you to read and parse XML files, but I was wondering if there's any way to edit/modify or create an XML file through code. Basically I need to store some data for my app, but using a database would be overkill, and I'd rather just store it in an XML file. However, I don't see anything in the documentation that allows for writing to an XML file. Is this possible? Or is it possible to edit comma-separated text files (or any text files)?

— asked October 23rd 2010 by Bill Labus
  • csv
  • edit
  • file
  • modify
  • text
  • write
  • xml
0 Comments

5 Answers

  • So I take it that's a no?

    — answered October 24th 2010 by Bill Labus
    permalink
    0 Comments
  • So I take it that's a no?

    — answered October 24th 2010 by Bill Labus
    permalink
    0 Comments
  • does it have to be XML? Use JSON it is supported

    — answered March 16th 2011 by Aaron Saunders
    permalink
    0 Comments
  • I haven't tried, but I think that should be possible. You can read XML file (using Ti.Filesystem) as a string and put it into variable, load XML structure from variable (using Ti.XML) and then manipulate XML using DOM methods. After you finished modifications of XML structure, you can overwrite old XML file by transforming XML structure into string representation that can be written in the file.

    Hope this helps.

    Ivan

    — answered March 17th 2011 by Ivan Škugor
    permalink
    0 Comments
  • I haven't tried, but I think that should be possible. You can read XML file (using Ti.Filesystem) as a string and put it into variable, load XML structure from variable (using Ti.XML) and then manipulate XML using DOM methods. After you finished modifications of XML structure, you can overwrite old XML file by transforming XML structure into string representation that can be written in the file.

    Hope this helps.

    Ivan

    — answered March 17th 2011 by Ivan Škugor
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.