我在 Xcode 中使用 pugiXML 并试图获取嵌入在文本标签中的段落。我使用的语言是 C++。我不认为这是重复的,因为我找到了 Visual Studio 的答案,但没有找到 Xcode 的答案,其他问题涉及提取单行而不是整个段落。
我显示的代码正确检索了标题和 ID,但无法提取文本。文本采用段落形式,两侧带有适当的文本标签。我的代码如下:
//open file
if (!doc.load_file("Sample.xml")){
cout << "Couldn't open file" << endl;
}
else{
xml_node page = doc.child("page");
//Correctly getting title and ID
cout << page.child_value("title") << endl;
cout << page.child_value("id") << endl;
//Problem line: can't get text.
cout << page.child_value("text") << endl;
}
最佳答案
我想通了。我没有找到正确的节点。
这是我应该做的:
xml_node text = doc.child("page").child("revision").child("text");
cout << text.child_value() << endl;
问题是我使用的方法。
关于c++ - 使用 pugiXML 提取文本标签中的段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33642094/