Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


xml winforms viewer

Posted on 2013-05-17
Medium Priority
Last Modified: 2013-05-22
I have a win form c# application that uses web services.  I am outputting the xml into a text area, but it isn't too readable.  Does anyone know of some control that I can use to view the xml better?  I can open it in internet explorer if i save it to a file, but I am not sure in C#.  I found a post, but the link for files was down.  This isn't huge for me, so I don't want to spend a ton of time.  i was hoping for something easy and pre-built.

Question by:jackjohnson44
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 42

Assisted Solution

sedgwick earned 2000 total points
ID: 39176723

Accepted Solution

jackjohnson44 earned 0 total points
ID: 39176771
I used the second link, then the second answer on that page.  Basically it creates a tree view control and sets its source to an xml string.  It was a little difficult because it was a console app that just opened.

Its easy to use.  You just need two functions.  In this example "treeXml" is a TreeView added to the page.

just call: SetTreeViewSourceToXml(xmlSource);

        private void SetTreeViewSourceToXml(string xmlSource)
            XmlDocument doc = new XmlDocument();
            catch (Exception err)

            ConvertXmlNodeToTreeNode(doc, treeXml.Nodes);

        private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes)
            TreeNode newTreeNode = treeNodes.Add(xmlNode.Name);

            switch (xmlNode.NodeType)
                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.XmlDeclaration:
                    newTreeNode.Text = "<?" + xmlNode.Name + " " +
                                       xmlNode.Value + "?>";
                case XmlNodeType.Element:
                    newTreeNode.Text = "<" + xmlNode.Name + ">";
                case XmlNodeType.Attribute:
                    newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name;
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    newTreeNode.Text = xmlNode.Value;
                case XmlNodeType.Comment:
                    newTreeNode.Text = "<!--" + xmlNode.Value + "-->";

            if (xmlNode.Attributes != null)
                foreach (XmlAttribute attribute in xmlNode.Attributes)
                    ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes);
            foreach (XmlNode childNode in xmlNode.ChildNodes)
                ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes);

LVL 42

Expert Comment

ID: 39176772
so did u manage to run it?
do u need any further help?

Author Comment

ID: 39176791
I'm good thanks.  That works great.  My code above will work.   I only marked that as the answer so people would see it.  I gave you the points.

Thanks and have a good weekend!!

Author Closing Comment

ID: 39186901
Thanks a lot! I want people to read my answer because it will save a lot of time.  The link was helpful but was geared toward a console app.

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question