Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/leethomason/tinyxml2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordota17 <chenguopingdota@163.com>2020-10-22 10:16:34 +0300
committerdota17 <chenguopingdota@163.com>2020-10-22 10:16:34 +0300
commitd59fd15db63aa93d979a4252dbea318116b194c9 (patch)
treec1a8db4ae32d37f3ddbabfb00b13eacdce69c18a
parent1aeb57d26bc303d5cfa1a9ff2a331df7ba278656 (diff)
skip comment node before get text
-rwxr-xr-xtinyxml2.cpp14
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;
}