tinyxml2/xmltest.cpp

71 lines
2.2 KiB
C++
Raw Normal View History

2011-12-28 22:36:55 +00:00
#include "tinyxml2.h"
#include <stdio.h>
#include <stdlib.h>
using namespace tinyxml2;
int main( int argc, const char* argv )
{
2012-01-15 02:08:12 +00:00
#if 0
2011-12-31 22:58:18 +00:00
{
static const char* test = "<!--hello world-->";
2011-12-28 22:36:55 +00:00
2011-12-31 22:58:18 +00:00
XMLDocument doc;
doc.Parse( test );
doc.Print( stdout );
}
{
2012-01-15 02:08:12 +00:00
static const char* test = "<!--hello world\n"
2012-01-19 01:43:40 +00:00
" line 2\r"
" line 3\r\n"
" line 4\n\r"
" line 5\r-->";
XMLDocument doc;
doc.Parse( test );
doc.Print( stdout );
}
#endif
{
2012-01-25 02:03:07 +00:00
static const char* test[] = { //"<element />",
//"<element></element>",
//"<element><subelement/></element>",
//"<element><subelement></subelement></element>",
2012-01-26 01:44:30 +00:00
// "<element><subelement><subsub/></subelement></element>",
//"<!--comment beside elements--><element><subelement></subelement></element>",
2012-01-25 02:03:07 +00:00
//"<!--comment beside elements, this time with spaces--> \n <element> <subelement> \n </subelement> </element>",
2012-01-26 01:44:30 +00:00
//"<element attrib1='foo' attrib2=\"bar\" ></element>",
//"<element attrib1='foo' attrib2=\"bar\" ><subelement attrib3='yeehaa' /></element>",
2012-01-25 02:03:07 +00:00
//"<element>Text inside element.</element>",
//"<element><b></b></element>",
2012-01-26 01:44:30 +00:00
//"<element>Text inside and <b>bolded</b> in the element.</element>",
//"<outer><element>Text inside and <b>bolded</b> in the element.</element></outer>",
"<element>This &amp; That.</element>",
"<element attrib='This&lt;That' />",
2012-01-19 01:55:48 +00:00
0
};
2012-01-22 02:45:16 +00:00
for( int i=0; test[i]; ++i ) {
2012-01-19 01:55:48 +00:00
XMLDocument doc;
2012-01-22 02:45:16 +00:00
doc.Parse( test[i] );
2012-01-25 02:03:07 +00:00
doc.Print();
2012-01-23 19:42:06 +00:00
printf( "----------------------------------------------\n" );
2012-01-19 01:55:48 +00:00
}
2011-12-31 22:58:18 +00:00
}
{
static const char* test = "<element>Text before.</element>";
XMLDocument doc;
doc.Parse( test );
XMLElement* root = doc.FirstChildElement();
XMLElement* newElement = doc.NewElement( "Subelement" );
root->InsertEndChild( newElement );
doc.Print();
}
{
XMLDocument* doc = new XMLDocument();
static const char* test = "<element><sub/></element>";
doc->Parse( test );
delete doc;
}
2011-12-28 22:36:55 +00:00
return 0;
}