basic text support
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 367f05c..0a02c4b 100644
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -132,9 +132,9 @@
char* XMLBase::Identify( XMLDocument* document, char* p, XMLNode** node )
{
XMLNode* returnNode = 0;
-
+ char* start = p;
p = XMLNode::SkipWhiteSpace( p );
- if( !p || !*p || *p != '<' )
+ if( !p || !*p )
{
return 0;
}
@@ -166,6 +166,12 @@
returnNode = new XMLElement( document );
p += elementHeaderLen;
}
+ // fixme: better text detection
+ else if ( (*p != '<') && IsAlphaNum( *p ) ) {
+ // fixme: this is filtering out empty text...should it?
+ returnNode = new XMLText( document );
+ p = start; // Back it up, all the text counts.
+ }
else {
TIXMLASSERT( 0 );
}
@@ -256,6 +262,22 @@
}
+// --------- XMLText ---------- //
+char* XMLText::ParseDeep( char* p )
+{
+ p = ParseText( p, &value, "<" );
+ // consumes the end tag.
+ if ( p && *p ) {
+ return p-1;
+ }
+ return 0;
+}
+
+
+void XMLText::Print( FILE* cfile, int depth )
+{
+ fprintf( cfile, value.GetStr() );
+}
// --------- XMLComment ---------- //
@@ -430,11 +452,19 @@
}
if ( firstChild ) {
- fprintf( cfile, ">\n" );
+ // fixme: once text is on, it should stay on, and not use newlines.
+ bool useNewline = firstChild->ToText() == 0;
+
+ fprintf( cfile, ">", Name() );
+ if ( useNewline ) fprintf( cfile, "\n" );
+
for( XMLNode* node=firstChild; node; node=node->next ) {
node->Print( cfile, depth+1 );
}
+
fprintf( cfile, "</%s>\n", Name() );
+ // fixme: see note above
+ //if ( useNewline ) fprintf( cfile, "\n" );
}
else {
fprintf( cfile, "/>\n" );