Dear All!

I am facing a small issue in showing xml in a proper format. I am getting proper xml data from my webservice. but after receiving it browser is treating it as a text and showing all test in single line. I want to show my xml data same as we open xml file in browser. How can i do this.

Here is my code

 $("#getXml").click(function () {
               var xmlhttp;
               xmlhttp = new XMLHttpRequest();
               xmlhttp.onreadystatechange = function () {
                   if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                       $("#divResult").html(xmlhttp.response);

                   }
               }
               //        alert("email.aspx?all=""&id="3"&item=""&type="");
               xmlhttp.open("GET", "e.aspx?all=&id='3'&item=&type=", true);
               xmlhttp.send();
           });

Regards

I used iframe to show the xml. and it is working fine.

I guess that the problem is that you are trying to display XML as XML in an HTML document.

It works like this: Your HTML document has already told your browser it's an HTML document. Therefore your browser will treat your document as an HTML document. If you want the XML to be displayed as how a plain XML file would be displayed if you'd open it with your browser, you need to create a whole new browser window and tell that window that it is an XML - not an HTML - file it should display, and then output the XML.

As M.Qawas Aslam says, using an iframe might do the trick. If that doesn't work, I suggest you open a whole new tab or browser window to display the XML. Or, alternatively, you could search for options to display XML as XML without opening a new window.

commented: Thanks for explanation :) +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.