From d59fd15db63aa93d979a4252dbea318116b194c9 Mon Sep 17 00:00:00 2001 From: dota17 Date: Thu, 22 Oct 2020 15:16:34 +0800 Subject: skip comment node before get text --- tinyxml2.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 1bacbe1..ed521f1 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1637,8 +1637,18 @@ float XMLElement::FloatAttribute(const char* name, float defaultValue) const const char* XMLElement::GetText() const { - if ( FirstChild() && FirstChild()->ToText() ) { - return FirstChild()->Value(); + /* skip comment node */ + const XMLNode* node = FirstChild(); + while (node) { + if (node->ToComment()) { + node = node->NextSibling(); + continue; + } + break; + } + + if ( node && node->ToText() ) { + return node->Value(); } return 0; } -- cgit v1.2.3