mirror of https://github.com/AxioDL/tinyxml2.git
test cases in progress
This commit is contained in:
parent
8a5dfee8ce
commit
dadcdfad4a
48
tinyxml2.cpp
48
tinyxml2.cpp
|
@ -143,16 +143,22 @@ char* XMLBase::Identify( XMLDocument* document, char* p, XMLNode** node )
|
|||
static const char* commentHeader = { "<!--" };
|
||||
static const char* dtdHeader = { "<!" };
|
||||
static const char* cdataHeader = { "<![CDATA[" };
|
||||
static const char* elementHeader = { "<" }; // and a header for everything else; check last.
|
||||
|
||||
static const int xmlHeaderLen = 5;
|
||||
static const int commentHeaderLen = 4;
|
||||
static const int dtdHeaderLen = 2;
|
||||
static const int cdataHeaderLen = 9;
|
||||
static const int elementHeaderLen = 1;
|
||||
|
||||
if ( XMLNode::StringEqual( p, commentHeader, commentHeaderLen ) ) {
|
||||
if ( StringEqual( p, commentHeader, commentHeaderLen ) ) {
|
||||
returnNode = new XMLComment( document );
|
||||
p += commentHeaderLen;
|
||||
}
|
||||
else if ( StringEqual( p, elementHeader, elementHeaderLen ) ) {
|
||||
returnNode = new XMLElement( document );
|
||||
p += elementHeaderLen;
|
||||
}
|
||||
else {
|
||||
TIXMLASSERT( 0 );
|
||||
}
|
||||
|
@ -222,6 +228,7 @@ void XMLNode::Print( FILE* fp, int depth )
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void XMLNode::PrintSpace( FILE* fp, int depth )
|
||||
{
|
||||
for( int i=0; i<depth; ++i ) {
|
||||
|
@ -270,6 +277,12 @@ char* XMLAttribute::ParseDeep( char* p )
|
|||
}
|
||||
|
||||
|
||||
void XMLAttribute::Print( FILE* cfile )
|
||||
{
|
||||
fprintf( cfile, "\"%s\"", value );
|
||||
}
|
||||
|
||||
|
||||
// --------- XMLElement ---------- //
|
||||
XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ),
|
||||
name( 0 ),
|
||||
|
@ -385,6 +398,29 @@ char* XMLElement::ParseDeep( char* p )
|
|||
}
|
||||
|
||||
|
||||
void XMLElement::Print( FILE* cfile, int depth )
|
||||
{
|
||||
PrintSpace( cfile, depth );
|
||||
fprintf( cfile, "<%s", Name() );
|
||||
|
||||
for( XMLAttribute* attrib=rootAttribute; attrib; attrib=attrib->next ) {
|
||||
fprintf( cfile, " " );
|
||||
attrib->Print( cfile );
|
||||
}
|
||||
|
||||
if ( firstChild ) {
|
||||
fprintf( cfile, ">/n" );
|
||||
for( XMLNode* node=firstChild; node; node=node->next ) {
|
||||
node->Print( cfile, depth+1 );
|
||||
}
|
||||
fprintf( cfile, "</%s>", Name() );
|
||||
}
|
||||
else {
|
||||
fprintf( cfile, "/>\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------- XMLDocument ----------- //
|
||||
XMLDocument::XMLDocument() :
|
||||
charBuffer( 0 )
|
||||
|
@ -407,10 +443,12 @@ bool XMLDocument::Parse( const char* p )
|
|||
XMLNode* node = 0;
|
||||
|
||||
char* q = Identify( this, charBuffer->mem, &node );
|
||||
root->InsertEndChild( node );
|
||||
node->ParseDeep( q );
|
||||
|
||||
return true;
|
||||
if ( node ) {
|
||||
root->InsertEndChild( node );
|
||||
node->ParseDeep( q );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ class XMLAttribute : public XMLBase
|
|||
public:
|
||||
XMLAttribute( XMLElement* element ) : value( 0 ), next( 0 ) {}
|
||||
virtual ~XMLAttribute() {}
|
||||
virtual void Print( FILE* cfile );
|
||||
|
||||
private:
|
||||
char* ParseDeep( char* p );
|
||||
|
@ -149,6 +150,7 @@ public:
|
|||
virtual ~XMLElement();
|
||||
|
||||
const char* Name() const { return name; }
|
||||
virtual void Print( FILE* cfile, int depth );
|
||||
|
||||
virtual XMLElement* ToElement() { return this; }
|
||||
bool Closing() const { return closing; }
|
||||
|
|
BIN
tinyxml2.suo
BIN
tinyxml2.suo
Binary file not shown.
14
xmltest.cpp
14
xmltest.cpp
|
@ -28,11 +28,15 @@ int main( int argc, const char* argv )
|
|||
}
|
||||
#endif
|
||||
{
|
||||
static const char* test = "<element />";
|
||||
|
||||
XMLDocument doc;
|
||||
doc.Parse( test );
|
||||
doc.Print( stdout );
|
||||
static const char* test[] = { "<element />",
|
||||
"<element></element>",
|
||||
0
|
||||
};
|
||||
for( const char* t=test[0]; *t; ++t ) {
|
||||
XMLDocument doc;
|
||||
doc.Parse( t );
|
||||
doc.Print( stdout );
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue