Wich is the best method to load a XML and parse its nodes?

Posted on 2005-05-17
Last Modified: 2010-04-16

I have a XML file:
<xml ....>
    <entity name='One'>
                <entityAttr name='Attr11' />
                <entityAttr name='Attr12' />

                <entityData name='Data11' />
                <entityData name='Data12' />

    <entity name='Two'>
                <entityAttr name='Attr21' />
                <entityAttr name='Attr22' />

                <entityData name='Data21' />
                <entityData name='Data22' />

I want to parse it and show:

       Some Data:

       Some Data:

Wich is the best method to do this? The fastest and the simpliest

Question by:mak730
    LVL 7

    Expert Comment

    Just use the frameworks System.XML (You will most likely just use the XML Reader).
    There are a ton of tutorials to show you how it works. This one looks fine.

    LVL 23

    Accepted Solution

                     XmlTextReader reader = new XmlTextReader(@"c:\entity.xml");
                      StringBuilder builder = new StringBuilder();
                      string padding = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                      while (reader.Read())
                            switch (reader.NodeType)
                                  case XmlNodeType.Element:
                                        if (reader.LocalName.StartsWith("entity"))
                                              string name = reader.LocalName.Replace("entity","");
                                              int depth = reader.Depth;
                                              if (name.Length != 0)
                                              if (reader.MoveToFirstAttribute())


    LVL 23

    Expert Comment

    using System.Xml;
    using System.IO;
    using System.Text;

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now