diff options
author | dota17 <chenguopingdota@163.com> | 2020-10-22 10:16:34 +0300 |
---|---|---|
committer | dota17 <chenguopingdota@163.com> | 2020-10-22 10:16:34 +0300 |
commit | d59fd15db63aa93d979a4252dbea318116b194c9 (patch) | |
tree | c1a8db4ae32d37f3ddbabfb00b13eacdce69c18a | |
parent | 1aeb57d26bc303d5cfa1a9ff2a331df7ba278656 (diff) |
skip comment node before get text
-rwxr-xr-x | tinyxml2.cpp | 14 |
1 files 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;
}
|