how to read through all elements of a XML file in C#

XML file:

hi, anyone know some function or class or some code to read all element under a Element(parent) like <A>. This parent can has many child and sub childs, and sub sub childs ........So when user select element A then program can list  a2 .....a5 and more in some sub level.
If user select a3, then the program list sub elements and its childs from a4.......
Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The concept is simple, but the most practical approach to coding this depends on your XML structure and what information you need. Anyway,

using System.Xml;

XmlDocument d = new XmlDocument();
d.LoadXml("xml goes here"); // You can also use Load() to load from a file

XmlNode root = d.DocumentElement;

Now, root.ChildNodes returns a collection of the immediate children of the root node - they're also XmlNodes with possible ChildNodes again. One approach is to go through ChildNodes recursively, another one involves using the XPath query language. Unless you know XPath, stick with going through the ChildNodes collections.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
therock_80Author Commented:
hi der_jth, can i use XML as a database? though i know it as data format, but if i can be a database, how can i make this xml file security. For example, i dont want any one access this XML file except me.
The answer to that question isn't particularly simple, but the short version: You can use XML documents as a sort of database - see the XmlDataDocument class and a good book. File security is achieved through normal file system access control lists.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.