本文整理汇总了C++中TiXmlComment::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlComment::Parse方法的具体用法?C++ TiXmlComment::Parse怎么用?C++ TiXmlComment::Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlComment
的用法示例。
在下文中一共展示了TiXmlComment::Parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
//
const char* demoStart =
"<?xml version=\"1.0\" standalone='no' >\n"
"<!-- Our to do list data -->"
"<ToDo>\n"
"<!-- Do I need a secure PDA? -->\n"
"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
"<Item priority=\"2\" distance='none'> Do bills </Item>"
"<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>"
"</ToDo>";
{
#ifdef TIXML_USE_STL
// What the todo list should look like after processing.
// In stream (no formatting) representation.
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
"<ToDo>"
"<!-- Do I need a secure PDA? -->"
"<Item priority=\"2\" distance=\"close\">Go to the"
"<bold>Toy store!"
"</bold>"
"</Item>"
"<Item priority=\"1\" distance=\"far\">Talk to:"
"<Meeting where=\"School\">"
"<Attendee name=\"Marple\" position=\"teacher\" />"
"<Attendee name=\"Voel\" position=\"counselor\" />"
"</Meeting>"
"<Meeting where=\"Lunch\" />"
"</Item>"
"<Item priority=\"2\" distance=\"here\">Do bills"
"</Item>"
"</ToDo>";
#endif
// The example parses from the character string (above):
#if defined( WIN32 ) && defined( TUNE )
_CrtMemCheckpoint( &startMemState );
#endif
{
// Write to a file and read it back, to check file I/O.
TiXmlDocument doc( "demotest.xml" );
doc.Parse( demoStart );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
}
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
printf( "** Printing via doc.Print **\n" );
doc.Print( stdout );
{
printf( "** Printing via TiXmlPrinter **\n" );
TiXmlPrinter printer;
doc.Accept( &printer );
fprintf( stdout, "%s", printer.CStr() );
}
#ifdef TIXML_USE_STL
{
printf( "** Printing via operator<< **\n" );
std::cout << doc;
}
#endif
TiXmlNode* node = 0;
TiXmlElement* todoElement = 0;
TiXmlElement* itemElement = 0;
// --------------------------------------------------------
// An example of changing existing attributes, and removing
// an element from the document.
// --------------------------------------------------------
// Get the "ToDo" element.
// It is a child of the document, and can be selected by name.
node = doc.FirstChild( "ToDo" );
//.........这里部分代码省略.........
示例2: main
int main()
{
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
//
const char* demoStart =
"<?xml version=\"1.0\" standalone='no' >\n"
"<!-- Our to do list data -->"
"<ToDo>\n"
"<!-- Do I need a secure PDA? -->\n"
"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
"<Item priority=\"2\" distance='none'> Do bills </Item>"
"<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>"
"</ToDo>";
#ifdef TIXML_USE_STL
/* What the todo list should look like after processing.
In stream (no formatting) representation. */
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
"<ToDo>"
"<!-- Do I need a secure PDA? -->"
"<Item priority=\"2\" distance=\"close\">Go to the"
"<bold>Toy store!"
"</bold>"
"</Item>"
"<Item priority=\"1\" distance=\"far\">Talk to:"
"<Meeting where=\"School\">"
"<Attendee name=\"Marple\" position=\"teacher\" />"
"<Attendee name=\"Voel\" position=\"counselor\" />"
"</Meeting>"
"<Meeting where=\"Lunch\" />"
"</Item>"
"<Item priority=\"2\" distance=\"here\">Do bills"
"</Item>"
"</ToDo>";
#endif
// The example parses from the character string (above):
#if defined( WIN32 ) && defined( TUNE )
QueryPerformanceCounter( (LARGE_INTEGER*) (&start) );
#endif
{
// Write to a file and read it back, to check file I/O.
TiXmlDocument doc( "demotest.xml" );
doc.Parse( demoStart );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
}
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
doc.Print( stdout );
TiXmlNode* node = 0;
TiXmlElement* todoElement = 0;
TiXmlElement* itemElement = 0;
// --------------------------------------------------------
// An example of changing existing attributes, and removing
// an element from the document.
// --------------------------------------------------------
// Get the "ToDo" element.
// It is a child of the document, and can be selected by name.
node = doc.FirstChild( "ToDo" );
assert( node );
todoElement = node->ToElement();
assert( todoElement );
// Going to the toy store is now our second priority...
// So set the "priority" attribute of the first item in the list.
node = todoElement->FirstChildElement(); // This skips the "PDA" comment.
assert( node );
itemElement = node->ToElement();
assert( itemElement );
itemElement->SetAttribute( "priority", 2 );
// Change the distance to "doing bills" from
// "none" to "here". It's the next sibling element.
itemElement = itemElement->NextSiblingElement();
assert( itemElement );
//.........这里部分代码省略.........