Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display XML from a String in iframe as XMLTree

I got an XML String from a gwt rpc call which i want to embed as xml page into an iframe. What i hope to see is the pretty printed xml tree with its collapsible structure the browsers offer surrounded by normal html stuff. So to say an inpage view of the xml.

I cannot use the srcdoc attribute of iframes because its not supported by IE8 (earliest needed to support) and the next problem is that no javascript libraries are allowed.

What I tried:

var iframeDocument = document.querySelector('#foo').contentWindow.document;
iframeDocument.open('text/xml', 'replace'); // Also tested without Args
iframeDocument.write(xmlcontent);
iframeDocument.close();

While Firefox atleast shows the XML tags but unformatted and without tree Chrome and IE remove the html tags and just lineup the contents.

Nextthing i tried is

<iframe id="xmlframe" src="test.xml" name="thexml">

Here Firefox does exactly what I want while the others produce the same output as before. So this is also not working and well i don't have the test.xml i just have a string variable along with other stuff returned...

Is this even possible? If not how would you open a new popup with the xml String as content?

like image 234
Dennis Ich Avatar asked Nov 11 '22 15:11

Dennis Ich


1 Answers

Like L.Monty said in the comments i would replace every < in your XML-string with &lt; and every > with &gt; so that the browser doesn't try to interpret all the tags as HTML.

For your tree-like view i would write my own function which adds a break after each XML end tag + an amount of spaces which you can count in a variable for each following XML-open tag. Dont Forget to reduce this Counter for each XML-Close tag as well.

like image 181
Khaine Avatar answered Nov 14 '22 21:11

Khaine