Javascript Convert String to XML, XML to String

Contoh String XML yang digunakan :

var xmlstring = ‘<?xml version="1.0"?>\
<root>\
<data>\
<row>\
<cell>Captain</cell>\
<cell>Bryophyllum</cell>\
<cell>Zucchini</cell>\
</row>\
</data>\
</root>’
;

Convert String to XML menggunakan Javascript:

var xmlobject = (new DOMParser()).parseFromString(xmlstring, “text/xml”);

Convert XML to String menggunakan Javascript:

var string = (new XMLSerializer()).serializeToString(xmlobject);

As Presented in captain.at

1 Response to “Javascript Convert String to XML, XML to String”


  1. 1 numericalexample.com

    This works only for Firefox, not for IE. Another limitation is that this only works on a full xml document, not on an xml element in the tree of an xml document

Leave a Reply