jQuery XMLDocuments and strings
<p>I have a dilemma that goes like this.</p>

<p>I have a string that represents XML. I want to manipulate that XML adding and updating nodes, and then I want the xml back as a string.</p>

<p>I have been working with javascript and jQuery and I have looked at several methods</p>

<p>WITH JQuery </p>

<pre><code>var x_raw = "&lt;?xml version='1.0'?&gt;&lt;Q id ='23'&gt;&lt;SQ id='201'&gt;&lt;GP id='0'&gt;&lt;/GP&gt;&lt;/SQ&gt;&lt;/Q&gt;"
var j_xml = $(x_raw)
.... Code for XML manipulation goes here ....
var x_string = (new XMLSerializer()).serializeToString(j_xml);
</code></pre>

<p>this produces a security exception in firebug </p>

<p>WITH Straight javascript</p>

<pre><code>var x_raw = "&lt;?xml version='1.0'?&gt;&lt;Q id ='23'&gt;&lt;SQ id='201'&gt;&lt;GP id='0'&gt;&lt;/GP&gt;&lt;/SQ&gt;&lt;/Q&gt;"
var xml = $.parseXML(x_raw);

newNode = xml.createElement("VALUE")
newText = xml.createTextNode("&lt;![CDATA[Whooppeee]]&gt;");

var insert = xml.getElementsByTagName('GP')[0].appendChild(newNode)
insert = insert.appendChild(newText)

var x_string = (new XMLSerializer()).serializeToString(xml);
</code></pre>

<p>This works but the CDATA code comes back as </p>

<p><code>&amp;lt;</code>![CDATA[Whoooppeee]] <code>&amp;gt;</code></p>

<p>I have tried the javascript escape trick </p>

<pre><code>newText = xml.createTextNode("\&lt;![CDATA[Whooppeee]]\&gt;")
</code></pre>

<p>doesn't work either</p>

<p>WITH jQuery traversal function on an XML Document...</p>

<pre><code>var x_raw = "&lt;?xml version='1.0'?&gt;&lt;Q id ='23'&gt;&lt;SQ id='201'&gt;&lt;GP id='0'&gt;&lt;/GP&gt;&lt;/SQ&gt;&lt;/Q&gt;"
var xml = $.parseXML(x_raw);
var collection = xml.filter("SQ")
</code></pre>

<p>produces a firebug error "xml.filter is not a function"
Any jQuery DOM traversal function produces the same error.</p>

<p>I am ready to resort to string manipulation functions which would be ugly!
So any help or hints that get me some logical outcome would very much appreciated.</p>

<p>Regards
with much gratitude and appreciation of the collective wisdom of the overflow crew !</p>

<p>Gus</p>
