user4945695
user4945695

Reputation:

Render an XML document

I have a variable with a string containing all my document like this :

var string = "<?xml version="1.0" encoding="utf-8"?> <title>Report</title><item><title>Hello</title></item><item><title>Wo</title></item><item><title>rld</title></item>";

I would like to open a new page with this report properly inserted and displayed but have no idea how to. How can I do ?

Thank you for your help.

Upvotes: 2

Views: 740

Answers (1)

AlliterativeAlice
AlliterativeAlice

Reputation: 12577

You can have the browser turn the string into an XML file like so:

var string = '<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" ><channel> <title>Report</title><item><title>Hello</title></item><item><title>Wo</title></item><item><title>rld</title></item></channel></rss>';

window.location = 'data:text/xml;charset=utf-8,' + string;

Or to open it in a new window/tab:

window.open('data:text/xml;charset=utf-8,' + string, '_blank');

Upvotes: 3

Related Questions