简体   繁体   中英

How can I serialize XML to a string in Mozilla Rhino (Javascript 1.6)?

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)?

XML.prettyPrinting = false;

应该做你想做的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM