hello,world working. Forgot how hard XML parsing can be.

This commit is contained in:
Lee Thomason 2012-01-11 15:55:05 -08:00
parent ce0763e34b
commit 85403d8935
3 changed files with 25 additions and 7 deletions

View File

@ -73,6 +73,13 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
void XMLNode::Print( FILE* fp, int depth ) void XMLNode::Print( FILE* fp, int depth )
{
for( XMLNode* node = firstChild; node; node=node->next ) {
node->Print( fp, depth );
}
}
void XMLNode::PrintSpace( FILE* fp, int depth )
{ {
for( int i=0; i<depth; ++i ) { for( int i=0; i<depth; ++i ) {
fprintf( fp, " " ); fprintf( fp, " " );
@ -138,6 +145,7 @@ char* XMLComment::ParseDeep( char* p )
XMLDocument::XMLDocument() : XMLDocument::XMLDocument() :
charBuffer( 0 ) charBuffer( 0 )
{ {
root = new XMLNode( this );
} }
@ -153,8 +161,11 @@ bool XMLDocument::Parse( const char* p )
{ {
charBuffer = CharBuffer::Construct( p ); charBuffer = CharBuffer::Construct( p );
XMLNode* node = 0; XMLNode* node = 0;
char* q = Identify( charBuffer->mem, &node ); char* q = Identify( charBuffer->mem, &node );
root->InsertEndChild( node );
node->ParseDeep( q ); node->ParseDeep( q );
return true; return true;
} }
@ -184,13 +195,19 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
// - Everthing else is unknown to tinyxml. // - Everthing else is unknown to tinyxml.
// //
const char* xmlHeader = { "<?xml" }; static const char* xmlHeader = { "<?xml" };
const char* commentHeader = { "<!--" }; static const char* commentHeader = { "<!--" };
const char* dtdHeader = { "<!" }; static const char* dtdHeader = { "<!" };
const char* cdataHeader = { "<![CDATA[" }; static const char* cdataHeader = { "<![CDATA[" };
if ( XMLNode::StringEqual( p, xmlHeader, 5 ) ) { static const int xmlHeaderLen = 5;
static const int commentHeaderLen = 4;
static const int dtdHeaderLen = 2;
static const int cdataHeaderLen = 9;
if ( XMLNode::StringEqual( p, commentHeader, commentHeaderLen ) ) {
returnNode = new XMLComment( this ); returnNode = new XMLComment( this );
p += commentHeaderLen;
} }
else { else {
TIXMLASSERT( 0 ); TIXMLASSERT( 0 );

View File

@ -48,7 +48,7 @@ class XMLNode
public: public:
XMLNode* InsertEndChild( XMLNode* addThis ); XMLNode* InsertEndChild( XMLNode* addThis );
void Print( FILE* cfile, int depth ); // prints leading spaces. virtual void Print( FILE* cfile, int depth );
protected: protected:
XMLNode( XMLDocument* ); XMLNode( XMLDocument* );
@ -90,6 +90,7 @@ protected:
XMLNode* next; XMLNode* next;
private: private:
void PrintSpace( FILE* cfile, int depth ); // prints leading spaces.
}; };
@ -100,7 +101,7 @@ public:
XMLComment( XMLDocument* doc ); XMLComment( XMLDocument* doc );
virtual ~XMLComment(); virtual ~XMLComment();
void Print( FILE* cfile, int depth ); virtual void Print( FILE* cfile, int depth );
protected: protected:
char* ParseDeep( char* ); char* ParseDeep( char* );

Binary file not shown.