Ruby
Ruby

Reputation: 969

Display XML file inside Div

I am trying to display an xml file inside a div, just like it opens in a browser(With colored tags,inner text & expand-collapse).Is it possible. For now, I am just displaying it in a label.

MY XML:

<EmployeeDetails>
  <Employee Uid="1546784553">
    <ID>100</ID>
    <Name>Pat</Name>
    <Salary>12000</Salary>
  </Employee>
   //....and so on
</EmployeeDetails>

ASPX:

<div id="divXml">
     <asp:UpdatePanel runat="server">
       <ContentTemplate>
         <pre>
           <asp:Label ID="lblXml" runat="server" Font-Size="Large"></asp:Label>
         </pre>
       </ContentTemplate>
     <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnView" EventName="Click" />
      </Triggers>
        </asp:UpdatePanel>
    </div>

CS:

private void ViewXml()
  {
    string strFile = Server.MapPath("~/XML/EmpXml.xml");
    if (File.Exists(strFile))
      { 
        string theXML = Server.HtmlEncode(File.ReadAllText
                         (Server.MapPath("~/XML/EmpXml.xml")));
        lblXml.Text = theXML;                 
      }
 }

Upvotes: 0

Views: 1186

Answers (2)

Jay Taplin
Jay Taplin

Reputation: 570

This question looks to be similar to your question; perhaps it will answer your question? How to style XML displayed in HTML?

Upvotes: 1

maccettura
maccettura

Reputation: 10819

Look into Google Code Pretifier or SyntaxHighlighter.

Unfortunately there is no native code highlighting because the browser is not equipped to know syntax highlighting for any old language, you must use a plugin!

Upvotes: 1

Related Questions