使用pugiXML在text标签中提取段落

时间:2015-11-11 00:13:45

标签: c++ xcode pugixml

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

1 个答案:

答案 0 :(得分:0)

我明白了。我没有进入正确的节点。

这就是我应该做的事情:

xml_node text = doc.child("page").child("revision").child("text");
cout << text.child_value() << endl;

问题是我使用的方法。