Displaying XML

Though supported in all major browsers, the raw XML files are, however, not displayed as HTML pages.

Viewing XML Files:

<?xml version="1.0" encoding="UTF-8"?>
 - <note>
       <to>Sapna</to>
       <from>Tom</from>
       <heading>Meeting</heading>
       <body>Monday at 11 AM!</body>
   </note>

When displayed in a browser, an XML document may appear with color-coded elements, and with a plus (+) or minus sign (-) to the left of the elements which when clicked expand or collapse the element structure.

Select “View Page Source” or “View Source” from the browser menu, to view raw XML source. Only the element text will be displayed in Safari 5 and earlier versions. Right-click the page and select “View Source”, to view the raw XML.

Viewing an Invalid XML File:

Some browsers report the error, some display it, or some display it incorrectly when an erroneous XML file is opened in a browser.

Example:

<?xml version="1.0" encoding="UTF-8"?>
 - <note>
       <to>Sapna</to>
       <from>Tom</sender>
       <heading>Meeting</heading>
       <body>Monday at 11 AM!</body>
   </note>

Why Does XML Display Like This?

Any information about how to display the data is not carried by an XML document. The author of the XML document invents the XML tags. Thus, a browser is not aware of whether a tag like <table> describes an HTML table or a coffee table. The browsers just display the XML document as it is, with no information about how to display the data. We can use XSLT, to style an XML document.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<nitf>
  <head>
    <title>CoronaVirus</title>
  </head>
  <body>
    <headline>
      <hl1>Millions Dead in World</hl1>
    </headline>
    <byline>
      <bytag>By Editor, Example Press</bytag>
    </byline>
    <dateline>
      <location>India</location>
      <date>Tuesday June 2 2020 8:28 IST</date>
    </dateline>
  </body>
</nitf>

Output: XML Tree:

Please Share