0

I'm having program like below. The concept is Read XML value from URL, but my program read the xml structure only, not the code datas. Like <Billing Address></Billing Address>... etc only. But the original XML value is <Billing Address>Strre1</Billing Address>. The Program does not read the inside value.

public static void zohoCRMReadAccounts()
{

    var val = auth();
    var val1= val[0];
    var val2= val[1];

    String xmlURL = "URL";
    XmlTextReader xmlReader = new XmlTextReader(xmlURL);
    while (xmlReader.Read())
    {
        switch (xmlReader.NodeType)
        {
            case XmlNodeType.Element: // The node is an element.
                Console.Write("<" + xmlReader.Name);
                // Read the attributes:
                while (xmlReader.MoveToNextAttribute()) 
                    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
}

Please help me to fix

2
  • 1
    Is there a specific reason why you are using the complicated XmlTextReader and not the much simpler XmlDocument or XDocument classes? Commented Sep 3, 2012 at 11:00
  • @DanielHilgarth If you know any simplest idea , then please share here Commented Sep 3, 2012 at 11:04

2 Answers 2

1

XML Elements cannot have spaces in their names. Try to remove them first

Sign up to request clarification or add additional context in comments.

Comments

0

First download the XML. Then Use like,

  try { 
    //read xml
    XmlDocument xdoc = new XmlDocument();
    xdoc.Load("XMLFilePath");
    XmlNodeList nodes = xdoc.SelectNodes(@"rss/channel/item");
    foreach (XmlNode node in nodes)
    {
      XmlNode titleNode = node.SelectSingleNode("title");
      string title = titleNode == null ? string.Empty : titleNode.InnerText;

      };

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.