Kaynağa Gözat

Merge pull request #840 from dota17/master

skip comment node before get text
Lee Thomason 5 yıl önce
ebeveyn
işleme
11376382fa
1 değiştirilmiş dosya ile 12 ekleme ve 2 silme
  1. 12 2
      tinyxml2.cpp

+ 12 - 2
tinyxml2.cpp

@@ -1655,8 +1655,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;
 }