Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
183
rated 0 times [  189] [ 6]  / answers: 1 / hits: 110326  / 12 Years ago, tue, march 27, 2012, 12:00:00

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.


More From » xml

 Answers
7

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);

[#86577] Monday, March 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
denzelc

Total Points: 637
Total Questions: 89
Total Answers: 88

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
denzelc questions
Wed, Jan 12, 22, 00:00, 2 Years ago
Thu, Sep 2, 21, 00:00, 3 Years ago
Thu, Sep 2, 21, 00:00, 3 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Fri, Jul 24, 20, 00:00, 4 Years ago
;