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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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();
}
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
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
yope, but it would be better to move if ( text == 0 ) inside GetText - I did it so.
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
Implemented & checked in. Thanks for the input!
lee