我正在使用 pugixml 来解析以下 xml:
<td class="title">
<div class="random" />
<a href="link">Link1 </a>
</td>
<td class="title">
<div class="random" />
<a href="link">Link2 </a>
</td>
ETC...
我想要 td class ="title" 中每个 'a href' 的值(出现次数不定),但只有第一个这样的实例。
我正在使用以下代码来尝试获取这些值:
pugi::xpath_node_set link_nodes = list_doc.select_nodes("//td[@class='title']");
for (pugi::xpath_node_set::const_iterator it = link_nodes.begin();it != link_nodes.end();++it)
{
pugi::xpath_node single_link_node = *it;
std::cout << single_link_node.node().select_single_node("//a").node().attribute("href").value()<<std::endl;
}
这似乎不起作用(它输出的次数,但其值似乎甚至没有出现在该元素中)。
谢谢。