我目前正在将 C++ 项目从 libxml2 移植到 pugixml。我有一个 XPath 查询,它曾经与 libxml2 完美配合,但使用 pugixml 返回零节点:
"//*[local-name(.) = '" + name + "']"
name
我要检索的元素的名称在哪里。任何人都可以阐明正在发生的事情吗?
代码:
const string path = "//*[local-name(.) = '" + name + "']";
std::cerr << path << std::endl;
try {
const xpath_node_set nodes = this->doc.select_nodes(path.c_str());
return nodes;
} catch(const xpath_exception& e) {
std::cerr << e.what() << std::endl;
throw logic_error("Could not select elements from document.");
}
名称: “页面”
XML:
<MyDocument>
<Pages>
<Page>
<Para>
<Word>Some</Word>
<Word>People</Word>
</Para>
</Page>
<Page>
<Para>
<Word>Some</Word>
<Word>Other</Word>
<Word>People</Word>
</Para>
</Page>
</Pages>
</MyDocument>