hello,world working. Forgot how hard XML parsing can be.
This commit is contained in:
27
tinyxml2.cpp
27
tinyxml2.cpp
@@ -73,6 +73,13 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
|
||||
|
||||
|
||||
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 ) {
|
||||
fprintf( fp, " " );
|
||||
@@ -138,6 +145,7 @@ char* XMLComment::ParseDeep( char* p )
|
||||
XMLDocument::XMLDocument() :
|
||||
charBuffer( 0 )
|
||||
{
|
||||
root = new XMLNode( this );
|
||||
}
|
||||
|
||||
|
||||
@@ -153,8 +161,11 @@ bool XMLDocument::Parse( const char* p )
|
||||
{
|
||||
charBuffer = CharBuffer::Construct( p );
|
||||
XMLNode* node = 0;
|
||||
|
||||
char* q = Identify( charBuffer->mem, &node );
|
||||
root->InsertEndChild( node );
|
||||
node->ParseDeep( q );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -184,13 +195,19 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
||||
// - Everthing else is unknown to tinyxml.
|
||||
//
|
||||
|
||||
const char* xmlHeader = { "<?xml" };
|
||||
const char* commentHeader = { "<!--" };
|
||||
const char* dtdHeader = { "<!" };
|
||||
const char* cdataHeader = { "<![CDATA[" };
|
||||
static const char* xmlHeader = { "<?xml" };
|
||||
static const char* commentHeader = { "<!--" };
|
||||
static const char* dtdHeader = { "<!" };
|
||||
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 );
|
||||
p += commentHeaderLen;
|
||||
}
|
||||
else {
|
||||
TIXMLASSERT( 0 );
|
||||
|
||||
@@ -48,7 +48,7 @@ class XMLNode
|
||||
public:
|
||||
|
||||
XMLNode* InsertEndChild( XMLNode* addThis );
|
||||
void Print( FILE* cfile, int depth ); // prints leading spaces.
|
||||
virtual void Print( FILE* cfile, int depth );
|
||||
|
||||
protected:
|
||||
XMLNode( XMLDocument* );
|
||||
@@ -90,6 +90,7 @@ protected:
|
||||
XMLNode* next;
|
||||
|
||||
private:
|
||||
void PrintSpace( FILE* cfile, int depth ); // prints leading spaces.
|
||||
|
||||
};
|
||||
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
XMLComment( XMLDocument* doc );
|
||||
virtual ~XMLComment();
|
||||
|
||||
void Print( FILE* cfile, int depth );
|
||||
virtual void Print( FILE* cfile, int depth );
|
||||
|
||||
protected:
|
||||
char* ParseDeep( char* );
|
||||
|
||||
BIN
tinyxml2.suo
BIN
tinyxml2.suo
Binary file not shown.
Reference in New Issue
Block a user