From 87e475a2800bc4bbd0c4623edfb486a6c6a314c6 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Tue, 20 Mar 2012 11:55:29 -0700 Subject: [PATCH] adding examples to the doc --- dox | 2 +- readme.txt | 36 +++++++++++++++++++++++++++++++++++- xmltest.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/dox b/dox index c9268e9..b7d19e5 100755 --- a/dox +++ b/dox @@ -184,7 +184,7 @@ SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. # Doxygen uses this value to replace tabs by spaces in code fragments. -TAB_SIZE = 8 +TAB_SIZE = 4 # This tag can be used to specify a number of aliases that acts # as commands in the documentation. An alias has the form "name=value". diff --git a/readme.txt b/readme.txt index 200805c..29ccf5f 100755 --- a/readme.txt +++ b/readme.txt @@ -83,7 +83,7 @@ Advantages of TinyXML-1
  • Support for some C++ STL conventions: streams and strings
  • Very mature and well debugged code base.
  • - +

    Features

    Memory Model

    @@ -188,6 +188,40 @@ an XML document. printer.PushAttribute( "foo", "bar" ); printer.CloseElement(); +

    Examples

    + +

    Load and parse an XML file.

    +@verbatim + /* ------ Example 1: Load and parse an XML file. ---- */ + { + XMLDocument doc; + doc.LoadFile( "dream.xml" ); + } +@endverbatim + +

    Lookup information.

    +@verbatim + /* ------ Example 2: Lookup information. ---- */ + { + XMLDocument doc; + doc.LoadFile( "dream.xml" ); + + // Structure of the XML file: + // - Element "PLAY" the root Element, which is the FirstChildElement of the Document + // - - Element "TITLE" child of the root PLAY Element + // - - - Text child of the TITLE Element + + // Navigate to the title, using the convenience function, with a dangerous lack of error checking. + const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText(); + printf( "Name of play (1): %s\n", title ); + + // Text is just another Node to TinyXML-2. The more general way to get to the XMLText: + XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText(); + title = textNode->Value(); + printf( "Name of play (2): %s\n", title ); + } +@endverbatim +

    Using and Installing

    There are 2 files in TinyXML-2: diff --git a/xmltest.cpp b/xmltest.cpp index ac5931b..f1b13e0 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -78,6 +78,32 @@ int main( int /*argc*/, const char* /*argv*/ ) _CrtMemCheckpoint( &startMemState ); #endif + /* ------ Example 1: Load and parse an XML file. ---- */ + { + XMLDocument doc; + doc.LoadFile( "dream.xml" ); + } + + /* ------ Example 2: Lookup information. ---- */ + { + XMLDocument doc; + doc.LoadFile( "dream.xml" ); + + // Structure of the XML file: + // - Element "PLAY" the root Element + // - - Element "TITLE" child of the root PLAY Element + // - - - Text child of the TITLE Element + + // Navigate to the title, using the convenience function, with a dangerous lack of error checking. + const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText(); + printf( "Name of play (1): %s\n", title ); + + // Text is just another Node to TinyXML-2. The more general way to get to the XMLText: + XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText(); + title = textNode->Value(); + printf( "Name of play (2): %s\n", title ); + } + { static const char* test[] = { "", "",