I have been using TinyXML to store data that now requires elements of text that are all spaces.
Saves work fine, loads on the other hand give me back null for the children of the element that stores the spaces.
The following is a quick hack I did to get it to work in my particular case, your milage may very and it will probably break other things, but ... works for me ...
diff -u -r1.1 tinyxmlparser.cpp
--- tinyxmlparser.cpp 8 Aug 2005 12:24:23 -0000 1.1
+++ tinyxmlparser.cpp 21 Aug 2005 16:37:48 -0000
@@ -1125,7 +1125,7 @@
const char* TiXmlElement::ReadValue( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
TiXmlDocument* document = GetDocument();
-
+ bool textFound = false; // notes if we've already found the text element or not
const char* pWithWhiteSpace = p;
// Read in text and elements in any order.
p = SkipWhiteSpace( p, encoding );
@@ -1133,6 +1133,7 @@
{
if ( *p != '<' )
{
+ textFound = true;
// Take what we have, make a text element.
TiXmlText* textNode = new TiXmlText( "" );
@@ -1164,6 +1165,23 @@
// Have we hit a new element or an end tag?
if ( StringEqual( p, "</", false, encoding ) )
{
+ if (!textFound && !TiXmlBase::IsWhiteSpaceCondensed() )
+ {
+ // Take what we have, make a text element.
+ TiXmlText* textNode = new TiXmlText( "" );
+
+ if ( !textNode )
+ {
+ if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
+ return 0;
+ }
+
+ // Special case: we want to keep the white space
+ // so that leading spaces aren't removed.
+ textNode->Parse( pWithWhiteSpace, data, encoding );
+
+ LinkEndChild( textNode );
+ }
return p;
}
else
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been using TinyXML to store data that now requires elements of text that are all spaces.
Saves work fine, loads on the other hand give me back null for the children of the element that stores the spaces.
The following is a quick hack I did to get it to work in my particular case, your milage may very and it will probably break other things, but ... works for me ...
diff -u -r1.1 tinyxmlparser.cpp
--- tinyxmlparser.cpp 8 Aug 2005 12:24:23 -0000 1.1
+++ tinyxmlparser.cpp 21 Aug 2005 16:37:48 -0000
@@ -1125,7 +1125,7 @@
const char* TiXmlElement::ReadValue( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
TiXmlDocument* document = GetDocument();
-
+ bool textFound = false; // notes if we've already found the text element or not
const char* pWithWhiteSpace = p;
// Read in text and elements in any order.
p = SkipWhiteSpace( p, encoding );
@@ -1133,6 +1133,7 @@
{
if ( *p != '<' )
{
+ textFound = true;
// Take what we have, make a text element.
TiXmlText* textNode = new TiXmlText( "" );
@@ -1164,6 +1165,23 @@
// Have we hit a new element or an end tag?
if ( StringEqual( p, "</", false, encoding ) )
{
+ if (!textFound && !TiXmlBase::IsWhiteSpaceCondensed() )
+ {
+ // Take what we have, make a text element.
+ TiXmlText* textNode = new TiXmlText( "" );
+
+ if ( !textNode )
+ {
+ if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
+ return 0;
+ }
+
+ // Special case: we want to keep the white space
+ // so that leading spaces aren't removed.
+ textNode->Parse( pWithWhiteSpace, data, encoding );
+
+ LinkEndChild( textNode );
+ }
return p;
}
else
Bah, squished whitespace in my whitespace patch! This url will get you a properly formatted diff
http://www.notresponsible.org/~bits/tinyxmlparser.cpp.patch