使用pugiXML提取文本标记中的段落

extracting paragraph in text tag using pugiXML

本文关键字:段落 pugiXML 提取 取文本 使用      更新时间:2023-10-16

我在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;

问题是我使用的方法。