0
<tours xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://api.contiki.com/schemas/v2/detailed_tours.xsd">
<tour>
  <id>290</id>
  <name>Peru Uncovered</name>
  <lowest_price>
    <code>11D15a</code>
  </lowest_price>
 </tour>
</tours>

I want to read Id, name and code. I am trying this code

XmlTextReader reader = new XmlTextReader(downloadfolder);

XmlDocument doc = new XmlDocument();
XmlNode node = doc.ReadNode(reader);

foreach (XmlNode chldNode in node.ChildNodes)
{
    string employeeName = chldNode.Attributes["name"].Value;
}

But i am getting null. Can anyone tell me how can i read the values? i can not use Linq as i am working in SSIS 2008 project which does not support linq.

Updated Answer

XmlTextReader reader = new XmlTextReader(downloadfolder);
while (reader.Read())
{
    switch (reader.NodeType)
    {
        case XmlNodeType.Element: // The node is an element.

            string node = reader.Name;
            if (node == "id")
            {
                string id = reader.ReadString();
            }
            if (node == "name")
            {
                string name = reader.ReadString();
            }
            if (node == "code")
            {
                string code = reader.ReadString();
            }
            break;
    }

I can read the values but how can i add these as a row in my data table?

Daniel
  • 9,491
  • 12
  • 50
  • 66
user3754676
  • 311
  • 4
  • 17

1 Answers1

0

here node type of "name" is element.

below code can be used for node type checking

XmlTextReader reader = new XmlTextReader ("<file name>");
            while (reader.Read()) 
            {
                switch (reader.NodeType) 
                {
                    case XmlNodeType.Element: 

Reference : http://support.microsoft.com/en-us/kb/307548

Sachin Gupta
  • 7,805
  • 4
  • 30
  • 45
  • this is very complicated how can i read the value if i find the element name "id" then how can i read the value – user3754676 Mar 30 '15 at 06:58
  • so you wanted to read xml into data-table then check this stack-over flow thread [http://stackoverflow.com/questions/9781796/code-for-reading-an-xml-file-into-a-datatable](http://stackoverflow.com/questions/9781796/code-for-reading-an-xml-file-into-a-datatable) – Sachin Gupta Mar 30 '15 at 07:31