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 L.Monty said in the comments i would replace every <
in your XML-string with <
and every >
with >
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.
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