3

I have used the following code for displaying My xmlstring retrieved by an AJAX call in a new window:

window.open('data:text/xml,' + encodeURIComponent( xmlstring ) );

It is working in Firefox only but I need to make it work in Chrome as well. I can not have a specific XSLT file for transformation, because the xmlstring will have dynamic structure, it will be different each time I call the controller. It is just a XML string that I want to show a in a new window. Can anyone advise?

Update: This is the error I get in Chrome:

This page contains the following errors:

error on line 1 at column 65425: Couldn't find end of Start Tag Loca Below is a rendering of the page up to the first error.

and I will see a messedup string which is not like a xml.

I do not know if it is related to xml structure but I found a link which says the above code is just working in firefox or Opera. Again I cannot use xslt so I do not know what to do.

Render XML document (obtained through ajax call) to a new window

Thank you for helping me! ;)

Community
  • 1
  • 1
Leila
  • 232
  • 6
  • 15

1 Answers1

0

If I type the following into the console in Chrome,

window.open('data:text/xml,' + encodeURIComponent( "<a><b><c/><d/></b><e/></a>") );

And click on the pop-up icon to allow the blocked window,

enter image description here

then I see a tab with a graphical rendition of the XML,

enter image description here

as expected.


Update

If the page contains the following error,

error on line 1 at column 65425: Couldn't find end of Start Tag Loca Below is a rendering of the page up to the first error.

then your XML is not well-formed. Try the well-formed example XML I show above. When you find that it works as expected, and when you consider the error message you're receiving, you'll see that the problem is not an XML rendering problem but rather an XML syntax problem in the data itself.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Thanks for your answer but, I have an update to my question. I put more details. Would you please take a look at it. thank you – Leila May 14 '15 at 01:30
  • My xml looks like < 13 ha I know that this value "< 13 ha " is causing the problem. But, why it is working in firefox? – Leila May 14 '15 at 02:13
  • Replace the `<` with `<` to make the XML be well-formed. If Firefox forgave the transgression, it might be because it was acting as it does when it renders HTML and tries to repair mistakes. It is, no doubt, however, a mistake that you should fix rather than rely on Firefox's behavior or expect it from other browsers. – kjhughes May 14 '15 at 02:39