Thursday, July 2, 2009

Simple Way To Output XML to Browser

I have seen many Blogs and Posts where people do lot of hard work just to display the XML onto the web page. Well its very easy but people dont know which TAG do this

When you paste the XML on a .htm file, browser renders the XML Attributes as HTML attributes and displays the output. It wont display the way you see in a notepad file or in Visual Studio.

Some time during XML programming (I mean reading/writing/parsing/traversing), we get an error saying some issue with XML, but we can't see the extire XML because browser renders like a html file.

Without wasting more time, in order to print or show the XML content on browser, put the entire XML content in <XMP></XMP> tag and see the magic.

Below is the XML which I had put in a web page with and following 2 images shows the difference.

Output without <XMP></XMP> Tag:

Output with <XMP></XMP> Tag:

Similar Tags:

Display XML to Browser,
Print XML to Browser,
Output XML to Browser,
Viewing XML file in Browser.