Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1452] Need way to serialize DOM trees back to XML on mobile (save XML output)

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:56:12.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
ComponentsAndroid
Labelsandroid, apidoc, ios, iphone, output, patch, serialize, xml
ReporterBrion Vibber
AssigneeDon Thorp
Created2011-04-15T02:53:12.000+0000
Updated2011-04-17T01:56:12.000+0000

Description

Titanium Mobile provides a DOM interface for working with XML trees, and a point to parse a string into XML: Titanium.XML.parseString. However there appears to be no way to serialize a DOM tree back to XML for output, such as saving to a file, sending over the network, saving in a database, or feeding through an event into a WebView.

Our StatusNet client application reads data from Atom feeds and caches the individual entries into a local database, which we currently can't do with no way to get flat XML back out of the DOM trees.

In Titanium Desktop, we use the XMLSerializer interface like this:

var xml = (new XMLSerializer()).serializeToString(node);

If the equivalent interface can't be simply exposed into the general namespace, it might be good to expose a minimal interface on Titanium.XML, perhaps like this:

var xml = Titanium.XML.serializeToString(node);

Comments

  1. Brion Vibber 2011-04-15

    Patch on my github branch:
    http://github.com/brion/titanium_mobile/commit/46ebc43e9e670259c39d790e2bbc9d03e707cbc2"> http://github.com/brion/titanium_mobile/commit/46ebc43e9e670259c39d...

    (Android and iPhone) Adds Titanium.XML.serializeToString() method to create an XML string from a DOM node or document.

    Sample implementation for
    https://appcelerator.lighthouseapp.com/projects/32238/tickets/1452-need-way-to-s"> https://appcelerator.lighthouseapp.com/projects/32238/tickets/1452-...
    erialize-dom-trees-back-to-xml-on-mobile-save-xml-output

    Appcelerator contributor license agreement has been signed - brion@status.net /
    brion@pobox.com

  2. Jeff Haynie 2011-04-15

    i will merge.
    thanks very much!

  3. Brion Vibber 2011-04-15

    I've updated my work branch so the Android implementation is compatible with 1.6 (the first version only worked on 2.2): http://github.com/brion/titanium_mobile/commits/xml-serialize"> http://github.com/brion/titanium_mobile/commits/xml-serialize

    Latest commit: http://github.com/brion/titanium_mobile/commit/37bec7a0055f99f6fdfa27a69201cba0a6c243ff"> http://github.com/brion/titanium_mobile/commit/37bec7a0055f99f6fdfa...

  4. Brion Vibber 2011-04-15

    Per Don's recommendation I've also added a demo/test case to the KitchenSink XML demos in my branch:
    http://github.com/brion/titanium_mobile/commit/1c6a5c916ccee3d80fc3504da97cefeb06a0c4fe"> http://github.com/brion/titanium_mobile/commit/1c6a5c916ccee3d80fc3...

    Note this branch currently also includes my fix for the other XML test cases on iOS -- ticket 1624:

    https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobile/tickets/1624-tidomnode-nextsibling-previoussibling-properties-skip-non-element-nodes-on-ios#ticket-1624-2"> https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobi...

  5. Brion Vibber 2011-04-15

    Cleaned up and separated the three pieces into three commits to make it easier to review:
    http://github.com/brion/titanium_mobile/commits/xml-serialize-updated"> http://github.com/brion/titanium_mobile/commits/xml-serialize-updated

    Android implementation:
    http://github.com/brion/titanium_mobile/commit/324e61363e0890bd9a8ccf1a743e315619946219"> http://github.com/brion/titanium_mobile/commit/324e61363e0890bd9a8c...

    iOS implementation:
    http://github.com/brion/titanium_mobile/commit/ecdf14ba53587981583f77d24b022c5a29562748"> http://github.com/brion/titanium_mobile/commit/ecdf14ba53587981583f...

    KitchenSink demo/test case:
    http://github.com/brion/titanium_mobile/commit/6d1c218841b8e606a48a2c1b69b2899ded5238c9"> http://github.com/brion/titanium_mobile/commit/6d1c218841b8e606a48a...

    The fix for the other XML test cases on iOS is separately linked on ticket 1624, so be aware that if that's not merged, the KitchenSink demo will throw a scary red error screen when run on iPhone.

  6. Brion Vibber 2011-04-15

    Is any further action required on this? Looks like it's been merged on iPhone, Android, & the KitchenSink tests.

  7. Brion Vibber 2011-04-15

    Here's another patch adding the new method to API docs:

    http://github.com/brion/titanium_mobile/commit/036bfaae37bc7d2d23341c8bfd6311c36a198c86"> http://github.com/brion/titanium_mobile/commit/036bfaae37bc7d2d2334...

    However I notice there's no way to override the 'since' version of 0.8 that's on the Ti.XML module: https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobile/tickets/1700-api-docs-dont-allow-for-setting-a-since-version-number-on-individual-methods-properties"> https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobi...

  8. Don Thorp 2011-04-15

    Merged documentation. Sending to QA.

  9. Thomas Huelbert 2011-04-15

    iOS 4.1 and 3.1.2; android 2.2 and 1.6

JSON Source