# How to read an XML file

**URL:** <https://forum.kirupa.com/t/how-to-read-an-xml-file/243713>\
**Category:** Uncategorized\
**Created:** [November 9, 2007, 8:43pm UTC](https://forum.kirupa.com/t/how-to-read-an-xml-file/243713 "2007-11-09T20:43:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![techie](https://avatars.discourse-cdn.com/v4/letter/t/71e660/32.png) [@techie](https://forum.kirupa.com/u/techie)\
**Post date:** [November 9, 2007, 8:43pm UTC](https://forum.kirupa.com/t/how-to-read-an-xml-file/243713/1 "2007-11-09T20:43:32Z")

</div>

Hi,

I’m trying to read an XML file. How do i read through all the child nodes.  
I have attached a sample of the XML file.  
Please help!

\<?xml version=“1.0” encoding=“UTF-8” ?\>

- \<Payment DocumentType=“XML” Count=“2”\>
- \<RejectAccount Date=“2006-11-11” Status=“Rejected”\>
- \<Transaction TranNum=“1” Date=“2005-02-11”\>  
\<ID\>112\</ID\>  
\<Name\>Helen Trent\</Name\>  
\<ValueDate\>2006-08-20\</ValueDate\>  
\<Credit\>1250.00\</Credit\>  
\</Transaction\>
- \<Transaction TranNum=“2” Date=“2006-04-11”\>  
\<ID\>10\</ID\>  
\<Name\>Sam Rivers\</Name\>  
\<ValueDate\>2005-08-20\</ValueDate\>  
\<Credit\>1251.00\</Credit\>  
\</Transaction\>  
\</RejectAccount\>  
\</Payment\>

This is my code:

static void Main(string[] args)  
{  
XmlDocument doc = new XmlDocument();  
doc.Load(“C:\file.xml”);

```
        XmlNodeList AcceptList = doc.GetElementsByTagName("RejectAccount");
        foreach (XmlNode node in RejectList)
        {
            XmlElement RejectAccountElement = (XmlElement)node;
            string ID = "";
            string Name = "";
            string ValueDate = "";
            string Credit = "";
          
           
                if (RejectAccountElement.HasChildNodes)
                {
                    
  ID = RejectAccountACHElement.GetElementsByTagName("ID")*.InnerText;
Name = RejectAccountElement.GetElementsByTagName("Name")*.InnerText;
ValueDate = RejectAccountElement.GetElementsByTagName("ValueDate")*.InnerText;
Credit = RejectAccountElement.GetElementsByTagName("Credit")*.InnerText;
                  
                }
           
                
   Console.WriteLine("{0} {1} {2} {3} ", ID, Name, ValueDate, Credit);
```
