/**
* Here's a code sample to convert xml string to dom, and xml dom
* back to string;
*/
<h1>XML DOM</h1>
<script>
var text = '<?xml version=\"1.0\"?>';
text = text + '<data>';
text = text + '<name>Lady Gaga</name>';
text = text + '<city>New York</city>';
text = text + '</data>';
var parser = new DOMParser();
<script>
var text = '<?xml version=\"1.0\"?>';
text = text + '<data>';
text = text + '<name>Lady Gaga</name>';
text = text + '<city>New York</city>';
text = text + '</data>';
var parser = new DOMParser();
// convert text string to dom
var dom = parser.parseFromString(text,'text/xml');
var dom = parser.parseFromString(text,'text/xml');
// convert back dom to string of text
alert((new XMLSerializer()).serializeToString(dom));
</script>
alert((new XMLSerializer()).serializeToString(dom));
</script>
No comments:
Post a Comment