1

I have a variable in javascript which has XML data. When I try to print it, it prints only values of XML data and doesn't print XML tags.

I have this function:

function printxml(xmlData,requestTag) {
    var myWindow=window.open('');
    myWindow.document.write("<div id='hii'>+"xmlData+"<div>");
}

Where xmldata contains:

<?xml version="1.0" encoding="UTF-8"?>
<book>
    <author>Sindhu</author>
    <BookName>BookName</BookName>
</book>

It prints only

SindhuBookName
Sander Steffann
  • 9,509
  • 35
  • 40
  • [how to display xml in javascript?](http://stackoverflow.com/questions/349250/how-to-display-xml-in-javascript) might help you – Satpal Jan 06 '14 at 10:30
  • Have you checked the source? I think you'll find your XML there. The text you see on the screen are the two text nodes in your XML. If you want to show the tags, you've got to escape them. – mcv Jan 06 '14 at 10:34

1 Answers1

3

I am no Javascript expert, but I guess this is because your browser won't show you what it considers HTML tags. I think that you need to escape them, so that you can see the whole XML string.

Try this : https://stackoverflow.com/a/5251551/2466911

Community
  • 1
  • 1
Martin
  • 1,868
  • 1
  • 15
  • 20