瀏覽代碼

skip comment node before get text

dota17 5 年之前
父節點
當前提交
d59fd15db6
共有 1 個文件被更改,包括 12 次插入2 次删除
  1. 12 2
      tinyxml2.cpp

+ 12 - 2
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;
 }