Karthiga aaru

Karthiga aaru

  • NA
  • 1
  • 5.3k

Need help to read from XML URL using C#?

Sep 7 2012 5:49 AM

I'm having below XML structure in URL. Now the problem is reading XML data. I can able to read the FL val ="ACCCOUNTID" data ie 12345. But can't able to read "Account Name" ie .. I need to read demo1 data ..only.

 <result>
<Accounts>
<row no="1">
<FL val="ACCOUNTID">12345</FL>
<FL val="Account Name">
<![CDATA[ demo1 ]]>
</FL>
</row>
<row no="2">
<FL val="ACCOUNTID">12345</FL>
<FL val="Account Name">
<![CDATA[ demo ]]>
</FL>
</row>
</Accounts>
</result>

My program is below :

String xmlZohoResponse = "http://localhost/demo.xml";
        XmlTextReader xmlReader = new XmlTextReader(xmlZohoResponse);
        while (xmlReader.Read())
        {
            switch (xmlReader.NodeType)
            {
                case XmlNodeType.Element: // The node is an element.
                    Console.Write("<" + xmlReader.Name);

                    while (xmlReader.MoveToNextAttribute()) // Read the attributes.
                        Console.Write(" " + xmlReader.Name + "='" + xmlReader.Value + "'");
                    Console.WriteLine(">");
                    break;
                case XmlNodeType.Text: //Display the text in each element.
                    Console.WriteLine(xmlReader.Value);
                    break;
                case XmlNodeType.EndElement: //Display the end of the element.
                    Console.Write("</" + xmlReader.Name);
                    Console.WriteLine(">");
                    break;
            }
        }
        Console.WriteLine("Press any key to continue…");
        Console.ReadLine(); //Pause

Answers (1)