-2

我有一些问题,也许是愚蠢的问题。

我有这个网址: http://flibusta.net/opds/opensearch?searchTerm =Тол&searchType=books

我想像这样解析响应:

string search_link = "http://flibusta.net/opds/opensearch?searchTerm=Тол&searchType=books";

_document = new XPathDocument(search_link);

XPathNavigator navigator = _document.CreateNavigator();
XmlNamespaceManager ns = new XmlNamespaceManager(navigator.NameTable);
XPathNodeIterator nodes = navigator.Select("/feed/title");

while (nodes.MoveNext())
{
        XPathNavigator currentNavigator = nodes.Current;
        string title = currentNavigator.Value;
        Trace.WriteLine(title);
}

但是节点返回零结果。无法理解我做错了什么。

谢谢,

帕维尔。

4

1 回答 1

5

忘记没有名称空间的 XML。试试下面的例子,它对我来说很好:

var document = new XPathDocument("http://flibusta.net/opds/opensearch?searchTerm=%D0%A2%D0%BE%D0%BB&searchType=books");
XPathNavigator navigator = document.CreateNavigator();
var ns = new XmlNamespaceManager(navigator.NameTable);
ns.AddNamespace("atom", "http://www.w3.org/2005/Atom");

XPathNodeIterator nodes = navigator.Select("/atom:feed/atom:title", ns);

while (nodes.MoveNext())
{
        XPathNavigator currentNavigator = nodes.Current;
        string title = currentNavigator.Value;
        Trace.WriteLine(title);
}
于 2012-06-21T16:03:07.700 回答