Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:59:46+00:00 2026-05-13T18:59:46+00:00

I have an XML document (in a .net C# web app) that I want

  • 0

I have an XML document (in a .net C# web app) that I want to display in its simplistic form (similar to IE). I need it to be browser independent (or as much as possible) and have a consistent display.

I have tried pushing the xml document through as “text/xml” and this is inconsistent and doens’t work in some browsers.

http://sources.redhat.com/ml/xsl-list/2002-02/msg00831.html
A link here provided a good way of transforming the XML to HTML/XHTML using stylesheets.
However the stylesheet provided didnt work.

First: Is this the best way to do it? Are there better solutions?
Second: If not, does anyone know where I can find the XSLT?

EDIT (clarification): The XSLT I refer to will transform the XML into the Internet Explorer style display of XML files.

Thanks in advance! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:59:46+00:00Added an answer on May 13, 2026 at 6:59 pm

    I decided my best approach (for my situation) was to write 2 simple C# methods to generate HTML from the XML on the server side. This helps reduce any reliance on browser displaying XML (Opera is Crazy!)

    (This example uses pretty simple formatting, which was fine for my situation.
    I loosely modelled it on IE’s display of XML.
    For others’ reference, here are the methods:

            /// <summary>
        /// Does a simple convert to display an Xml document in HTML.
        /// </summary>
        /// <param name="xmlString"></param>
        private static string ConvertXmlToHtml(string xmlString)
        {
            StringBuilder html = new StringBuilder();
    
            html.AppendLine("<HTML>");
            html.AppendLine("<HEAD><TITLE>Xml Document</TITLE></HEAD>");
    
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlString);
    
            html.AppendLine(ConvertXmlElementToHTML(1, doc.DocumentElement));
    
            html.AppendLine("</HTML>");
    
    
            return html.ToString();
        }
    
        /// <summary>
        /// Converts an XML element (and all of its children) to HTML.
        /// This is a recursive method.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        private static string ConvertXmlElementToHTML(int level, XmlNode element)
        {
            int padding = level; // padding (cm == level).
    
            StringBuilder returnHTML = new StringBuilder();
            if (element is XmlElement)
            {
                // Formatting for symbols to simplify code below.
                string close_bracket = "<SPAN style=\"color: blue\">&gt;</SPAN>";
                string close_bracket_no_children = "<SPAN style=\"color: blue\"> /&gt;</SPAN>";
                string open_bracket = "<SPAN style=\"color: blue\">&lt;</SPAN>";
                string open_bracket_end_el = "<SPAN style=\"color: blue\">&lt;/</SPAN>";
                string el_name = "<SPAN style=\"color: brown\">" + element.Name + "</SPAN>";
                string quote = "<SPAN style=\"color: blue\">\"</SPAN>";
                string equals_sign = "<SPAN style=\"color: blue\">=</SPAN>";
    
                // Open Element.
                returnHTML.AppendLine("<DIV style=\"margin-left: " + padding + "cm\">" + open_bracket + el_name);
    
                // Print element attributes.
                foreach(XmlAttribute att in element.Attributes)
                {
                    returnHTML.AppendLine(" <SPAN style=\"color: brown\">" + att.Name + "</SPAN>" + equals_sign + quote + "<SPAN style=\"color: black; text-weight: bold\">" + att.Value + "</SPAN>" + quote);
                }
    
                // If no children, we end the element here with a '/ >'
                // otherwise, we close the element and start to write children '>'
                if (element.ChildNodes.Count == 0)
                {
                    returnHTML.AppendLine(close_bracket_no_children + "</DIV>");
                }
                else
                {
                    returnHTML.AppendLine(close_bracket + "</DIV>");
                }
    
                // Print Children. (Recursive call). Note location is IMPORTANT: we need child elements
                // to print after the element is opened and before the element is closed.
                foreach (XmlNode child in element.ChildNodes)
                {
                    returnHTML.AppendLine(ConvertXmlElementToHTML(level + 1, child));
                }
    
                // If we have printed child elements, we need to print a closing element tag.
                if (element.ChildNodes.Count > 0)
                {
                    returnHTML.AppendLine("<DIV style=\"margin-left: " + padding + "cm\">" + open_bracket_end_el + el_name + close_bracket + "</DIV>");
                }
            }
    
            // Return a string of HTML that will display elements at this level and below (child nodes).
            return returnHTML.ToString();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have some legacy ASP.NET 2.0 code that uses the ASP Xml web
I have an XML document that I'm trying to search through. The Main structure
I have an XML document, and I want to print the tag names and
I have an XML document that I generate from an Entity Framework object. The
I have an XML document that I load in and try to search with
I have an XML document with a section similar to the following: <release_list> <release>
I have a lot of XSL files in my ASP.NET web app. A lot.
I have an ASP.Net MVC site that generates a Microsoft Excel 2003 XML formatted
I have an XML document that needs to pass text inside an element with
I have the following xml that's sent to me from a web service. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.