tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

XML comment node prevent GetText()

Open Fuyutsubaki opened this issue 6 years ago • 0 comments

#include <tinyxml2.h>
#include <iostream>
#include <cassert>
int main(){
    // normal case
    {
        tinyxml2::XMLDocument doc;
        doc.Parse("<a>ABC</a>");
        auto a = doc.FirstChildElement();
        assert(a->GetText() == std::string("ABC"));  // ok
    }
    // comment prevent GetText()
    {
        tinyxml2::XMLDocument doc;
        doc.Parse("<a><!--ABC-->XYZ</a>"); // comment out "ABC"
        auto a = doc.FirstChildElement();
        //assert(a->GetText() == std::string("XYZ"));  // expected return "XYZ"
        assert(a->GetText() == nullptr);               // but, return nullptr
    }
}

GetText() : https://github.com/leethomason/tinyxml2/blob/7.0.1/tinyxml2.cpp#L1580

FirstChild() is comment node. so, GetText() return nullptr. XML comment node prevent GetText(). it is hard to predict.

Getting text using gettext () in the current implementation leads to an unfortunate accident

Fuyutsubaki avatar Jun 21 '19 10:06 Fuyutsubaki