View Single Post
Old 01-09-2013, 01:43 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,236
Thanks: 59
Thanked 3,997 Times in 3,966 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Wrong forum. This should be in the general JavaScript forum, I think. It has nothing to do with either JSON or the DOM.

And as I said, encodeURI, encodeURIComponent, and escape are all completely wrong solutions, as they convert (for example) < to %3C instead of to the &lt; that is required by XML.

And I don't think you would want Object.HTMLEncode, in any case. Since you say you want to produce XML from (presumably) a tree of objects, you would presumably do it with an object-to-xml method, and I think you will find that all browser can do that for you.
Code:
For Internet Explorer:
var string = xmlNode.xml;
For others:
var string = (new XMLSerializer()).serializeToString(xmlNode);
where of course xmlNode can be a root node of an entire tree to be converted to XML string.

And I'm pretty darned sure that either of those will happily handle encoding the needed entities.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote