1

有人可以解释一下为什么这不起作用吗?

XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("Bing2_ss.xml");

                    //Instantiate an XmlNamespaceManager object. 
                    XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable);
                    //Add the namespaces used in feed to the XmlNamespaceManager.
                    //xmlnsManager.AddNamespace("base", "https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Composite");
                    xmlnsManager.AddNamespace("m",   "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
                    xmlnsManager.AddNamespace("d",   "http://schemas.microsoft.com/ado/2007/08/dataservices/");
                    xmlnsManager.AddNamespace(String.Empty, "http://www.w3.org/2005/Atom");

                    XmlNodeList nodeList;
                    XmlElement root = xmlDoc.DocumentElement;
                    nodeList = root.SelectNodes("//m:properties/d:WebTotal", xmlnsManager);
                    foreach (XmlNode nd in nodeList)
                    {
                        System.Console.WriteLine(nd.InnerText);
                    }

这是原始 xml: http: //gezond-afslanken.info/bing2_ss.xml

4

1 回答 1

2

您的一个命名空间上有一个额外的斜杠。尝试

xmlnsManager.AddNamespace("d","http://schemas.microsoft.com/ado/2007/08/dataservices");
于 2012-08-15T16:12:16.213 回答