0

我有像下面这样的程序。这个概念是从 URL 读取 XML 值,但我的程序只读取 xml 结构,而不是代码数据。仅喜欢<Billing Address></Billing Address>...等。但原始 XML 值为<Billing Address>Strre1</Billing Address>. 程序不读取内部值。

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
}

请帮我修复

4

2 回答 2

1

XML 元素的名称中不能有空格。尝试先删除它们

于 2012-09-03T11:22:40.383 回答
0

首先下载 XML。然后像这样使用,

  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;

      };

}

于 2012-09-03T11:13:05.890 回答