Menu

implement GetText

Developer
Anonymous
2005-05-07
2013-05-20
  • Anonymous

    Anonymous - 2005-05-07

    There are so many people who want to get text in a convenient way, maybe this may be useful in the next version of tinyxml?

    char *TiXmlElement::GetText()
    {
        return (char *)(TiXmlText *)(FirstChild()->ToText())->Value();
    }

     
    • Lee Thomason

      Lee Thomason - 2005-05-14

      I'm totally up for considering this. But I have this concerns:

      How to handle:
      <foo> This is <bold>bold</bold> text.</foo>

      If you GetText() on "foo", what do you get back? "This is"? "This is text"? "This is <bold>bold</bold> text."? All have pretty serious drawbacks and can be very misleading.

      lee

       
      • Ellers

        Ellers - 2005-05-14

        Good point.
        But I think it is a common case to have a node like:

          <message>Hello</message>

        It seems a very useful/reasonable call to do to get the text of the first child.

        A "strawman" position (ie something to start with; knock it down if you like):

          someNode->GetText() returns the text of the first child of someNode IF someNode is an element whose first child is a text node.

        Error handling is a bit of a pain.

        e.g.
          text = pElement->GetText( );
          if ( text == 0 )
          {
            TiXmlGetLastError()
          }

        or
          bool result = pElement->GetText(&text)
        or
          use exceptions.

        I like the first option.

        WDYT?
        Ellers

         
    • Anonymous

      Anonymous - 2005-05-16

      yope, but it would be better to move  if ( text == 0 ) inside GetText - I did it so.

       
    • Lee Thomason

      Lee Thomason - 2005-05-26

      The more I thought about it, the more I liked the "returns the text of the first child of someNode IF someNode is an element whose first child is a text node" approach.

      Hopefully, adding GetText won't confuse the ToText() and Text() problem. Ughh.

      I haven't a decent little batch of changes - I'll try to get that in soon.

      lee

       
    • Lee Thomason

      Lee Thomason - 2005-06-13

      Implemented & checked in. Thanks for the input!

      lee

       

Log in to post a comment.

MongoDB Logo MongoDB