Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XML Serialization in Rhino 1.6

196 views
Skip to first unread message

dbha...@gmail.com

unread,
Oct 25, 2013, 6:15:19 PM10/25/13
to
I need to serialize a Javascript XML DOM object to an XML string.

Unfortunately, the only option for doing so in the version of Rhino I'm stuck with (implements Javascript 1.6) appears to be E4X and its toXMLString() method. This method does produce an XML string, but one formatted for human reading, with whitespace where it shouldn't have any.

Example - The output I want:

<Raster id="2" guid="12345" comment="">54321<Matrix>7|0|0|7|651|869</Matrix><MetaData/></Raster>

The output I get:

<Raster id="2" guid="12345" comment="">
54321
<Matrix>7|0|0|7|651|869</Matrix>
<MetaData/>
</Raster>

The whitespace before "54321" is significant and causes problems later when the output XML gets parsed.

I've been looking for an alternative XML serialization, but nothing seems to be available for this older Rhino version.

XMLSerializer would be ideal but it's not available in Rhino 1.6.

The XPCOM XMLSerializer from Mozilla's xmlextras would do the job as well, but the XPCOM Components object doesn't exist in Rhino 1.6.

Does anyone have any ideas where I could get an XML serializer that properly preserves whitespace and works with Alfresco's Rhino (Javascript 1.6)?

Any assistance appreciated.


Dan Hankins

ehr...@gmail.com

unread,
Oct 27, 2013, 12:47:21 PM10/27/13
to
Why does your XML need to be pretty printed?

dbha...@gmail.com

unread,
Oct 30, 2013, 1:12:23 PM10/30/13
to
On Sunday, October 27, 2013 9:47:21 AM UTC-7, ehr...@gmail.com wrote:
> Why does your XML need to be pretty printed?

I must not have explained clearly. Of the two example outputs I gave, the one I want is the one that's *not* pretty-printed.

There doesn't seem to be any way in Javascript 1.6 to turn an XML DOM object into an XML string without pretty-printing it. E4X pretty-prints the DOM subtree. I want something that *doesn't* pretty-print.

The only option I've seen to do what I want in Rhino involves calling Java classes from my Javascript... in which case I'd be better off just rewriting my function in Java. I'd hoped to avoid that.

dzul...@apigee.com

unread,
Feb 15, 2014, 8:57:36 AM2/15/14
to
0 new messages