Search code examples
c++xmlparsingpugixml

Recursive pugixml, can't get values


Well, I got code

pugi::xml_node text = doc.child("text").child("girl");

for (int i = 0; i < situations.size(); i++)
{
    std::cout << situations[i] << std::endl;
    text = text.child(situations[i].c_str()); // problem
}

After that code, I can't get any values from text, but straight using like

doc.child("text").child("girl").child_value("day1")

Is working. Need help. Thanks.


Solution

  • Instead of text.value(), you should use either text.child_value() or text.text().get().

    child_value("a") is equivalent to child("a").child_value(), not child("a").value(). The reason is that text is located in special PCDATA nodes - child_value() usually is the same as first_child().value().