2015-11-11 33 views
1

我在Xcode中使用pugiXML,並試圖獲取嵌入在文本標籤中的段落。我使用的語言是C++。我不認爲這是重複的,因爲我找到了Visual Studio的答案,但沒有爲Xcode和其他問題處理提取單行而不是整個段落。使用pugiXML提取文本標籤中的段落

我已經正確顯示的代碼檢索標題和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; 
} 

回答

0

我想通了。我沒有深入到正確的節點。

這是我應該做的事情:

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

,並在問題是,我使用的方法。