現在、C++ プロジェクトを libxml2 から pugixml に移植しています。私はlibxml2で完全にうまく機能していたXPathクエリを持っていますが、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>