Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

GetText() only works for the FirstChild node

Developer
algorith
2010-09-24
2013-05-20
  • algorith
    algorith
    2010-09-24

    Hi - nice job.  I was recently surprised to find that GetText() only works "If the first child of 'this' is a TiXmlText" (from tinyxml.h). Being somewhat new to the project, I was wondering if this is a structural requirement? From what I can tell nothing would be broken by the following:

    Change from (existing)

        [b]const TiXmlNode* child = this->FirstChild();
        if ( child ) [/b]{
            const TiXmlText* childText = child->ToText();
            if ( childText ) {
                return childText->Value();
            }
        }
        return 0;
    

    to (proposed)

        [b]for( const TiXmlNode* child = this->FirstChild();  child != 0;  child = this->IterateChildren(child))[/b]
        {
            const TiXmlText* childText = child->ToText();
            if ( childText ) {
                return childText->Value();
            }
        }
        return 0;
    

    Or, now that this message is written, it occurs to me that possibly two new functions would be appropriate, GetFirstText() and GetNextText()…which is getting pretty close to the existing ability to simply iterate through all the nodes that are text elements.  Hmm.