Search code examples
c++xcodepugixml

extracting paragraph in text tag using pugiXML


I'm using pugiXML in Xcode and am trying to get paragraphs that are embedded within the text tags. Language I'm using is C++. I do not think this is a duplicate because I've found answers for Visual Studio but not for Xcode and other questions deal with extraction of single lines not entire paragraphs.

The code I've shown correctly retrieves the title and ID but can't extract the text. Text is in the form of paragraphs flanked by the appropriate text tags. My code is as follows:

//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;
}

Solution

  • I figured it out. I was not getting down to the correct node.

    This is what I should be doing:

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

    and in the question is the approach that I used.