I want to convert an xml element like this:
<asin>B0013FRNKG</asin>
to string in javascript
I used XMLSerializer
:
new XMLSerializer().serializeToString(xml);
the string only shows on alert() and in the console. On the page it just says
[object Element][object Element]
I want to get the string.
XML Stringify is easy to use tool to convert XML to XML String while escaping special characters. Copy, Paste and Stringify.
In this article, you will learn three ways to read XML files as String in Java, first by using FileReader and BufferedReader, second by using DOM parser, and third by using open-source XML library jcabi-xml.
Open our free XML to HTML converter website. Click inside the file drop area to upload XML file or drag & drop XML file. Click on Convert button. Your XML files will be uploaded and converted to HTML result format.
You haven't told us how you go about displaying that object. XMLSerializer works on DOM nodes, so your object has to be added somewhere, for example:
document.getElementById('SomeDiv').appendChild(xml);
and if you just want the full xml string to be displayed:
var xmlText = new XMLSerializer().serializeToString(xml); var xmlTextNode = document.createTextNode(xmlText); var parentDiv = document.getElementById('SomeDiv'); parentDiv.appendChild(xmlTextNode);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With