From 8a0975dfa741097d66afda24e872600f0eac3339 Mon Sep 17 00:00:00 2001 From: "Lee Thomason (grinliz)" Date: Sat, 31 Mar 2012 20:09:20 -0700 Subject: [PATCH 1/3] minor warning fix --- tinyxml2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index eda2200..9e92ae2 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1576,7 +1576,7 @@ void XMLPrinter::PrintString( const char* p, bool restricted ) // Check for entities. If one is found, flush // the stream up until the entity, write the // entity, and keep looking. - if ( flag[*q] ) { + if ( flag[(unsigned)(*q)] ) { while ( p < q ) { Print( "%c", *p ); ++p; From 6a22be220ab6dc09d45ea2f53ea5ef023be83096 Mon Sep 17 00:00:00 2001 From: "Lee Thomason (grinliz)" Date: Wed, 4 Apr 2012 12:39:05 -0700 Subject: [PATCH 2/3] Added proper examples, integrated them into xmltest, and make them part of the build. --- dox | 6 ++-- readme.txt | 6 ++++ tinyxml2.h | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ xmltest.cpp | 73 ++++++++++++++++++++++++++++-------------- 4 files changed, 150 insertions(+), 27 deletions(-) diff --git a/dox b/dox index 108c6e2..9568fa9 100755 --- a/dox +++ b/dox @@ -32,7 +32,7 @@ PROJECT_NAME = "TinyXML-2" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 0.9.2 +PROJECT_NUMBER = 0.9.2 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer @@ -721,7 +721,7 @@ EXCLUDE_SYMBOLS = # directories that contain example code fragments that are included (see # the \include command). -EXAMPLE_PATH = +EXAMPLE_PATH = . # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp @@ -1040,7 +1040,7 @@ BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members # to the contents of the HTML help documentation and to the tree view. -TOC_EXPAND = NO +TOC_EXPAND = YES # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated diff --git a/readme.txt b/readme.txt index 4fc5d9c..ec2d015 100755 --- a/readme.txt +++ b/readme.txt @@ -8,6 +8,12 @@ easily integrated into other programs. The master is hosted on github: github.com/leethomason/tinyxml2 +The online HTML version of these docs: +http://grinninglizard.com/tinyxml2docs/index.html + +Where examples are in the "related pages" tab: +http://grinninglizard.com/tinyxml2docs/pages.html +

What it does.

In brief, TinyXML parses an XML document, and builds from that a diff --git a/tinyxml2.h b/tinyxml2.h index ae20e18..121fe03 100644 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -39,6 +39,7 @@ distribution. #include // Needed by mac. #endif + /* TODO: add 'lastAttribute' for faster parsing. TODO: intern strings instead of allocation. @@ -1251,5 +1252,96 @@ private: } // tinyxml2 +// What follows is the docs for the examples. +// I'd like the docs to be just before the +// actual examples in xmltest.cpp, but I +// can't seem to get doxygen to do that. It +// would be a wonderful patch if anyone figures +// it out. + +/** @page Example-1 Load an XML File + * @dontinclude ./xmltest.cpp + * Basic XML file loading. + * The basic syntax to load an XML file from + * disk and check for an error. (ErrorID() + * will return 0 for no error.) + * @skip example_1() + * @until } + */ + + +/** @page Example-2 Parse an XML from char buffer + * @dontinclude ./xmltest.cpp + * Basic XML string parsing. + * The basic syntax to parse an XML for + * a char* and check for an error. (ErrorID() + * will return 0 for no error.) + * @skip example_2() + * @until } + */ + +/** @page Example-3 Get information out of XML + @dontinclude ./xmltest.cpp + In this example, we navigate a simple XML + file, and read some interesting text. Note + that this is examlpe doesn't use error + checking; working code should check for null + pointers when walking an XML tree, or use + XMLHandle. + + (The XML is an excerpt from "dream.xml"). + + @skip example_3 + @until "; + + The structure of the XML file is: + +
    +
  • (declaration)
  • +
  • (dtd stuff)
  • +
  • Element "PLAY"
  • +
      +
    • Element "TITLE"
    • +
        +
      • Text "A Midsummer Night's Dream"
      • +
      +
    +
+ + For this example, we want to print out the + title of the play. The text of the title (what + we want) is child of the "TITLE" element which + is a child of the "PLAY" element. + + We want to skip the declaration and dtd, so the + method FirstChildElement() is a good choice. The + FirstChildElement() of the Document is the "PLAY" + Element, the FirstChildElement() of the "PLAY" Element + is the "TITLE" Element. + + @until ( "TITLE" ); + + We can then use the convenience function GetText() + to get the title of the play. + + @until title ); + + Text is just another Node in the XML DOM. And in + fact you should be a little cautious with it, as + text nodes can contain elements. + + @verbatim + Consider: A Midsummer Night's Dream + @endverbatim + + It is more correct to actually query the Text Node + if in doubt: + + @until title ); + + Noting that here we use FirstChild() since we are + looking for XMLText, not an element, and ToText() + is a cast from a Node to a XMLText. +*/ #endif // TINYXML2_INCLUDED diff --git a/xmltest.cpp b/xmltest.cpp index 20e3fa9..bb5bdfb 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -71,6 +71,51 @@ void NullLineEndings( char* p ) } +// Comments in the header. (Don't know how to get Doxygen to read comments in this file.) +int example_1() +{ + XMLDocument doc; + doc.LoadFile( "dream.xml" ); + + return doc.ErrorID(); +} + + +// Comments in the header. (Don't know how to get Doxygen to read comments in this file.) +int example_2() +{ + static const char* xml = ""; + XMLDocument doc; + doc.Parse( xml ); + + return doc.ErrorID(); +} + + +int example_3() +{ + static const char* xml = + "" + "" + "" + "A Midsummer Night's Dream" + ""; + + XMLDocument doc; + doc.Parse( xml ); + + XMLElement* titleElement = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" ); + const char* title = titleElement->GetText(); + printf( "Name of play (1): %s\n", title ); + + XMLText* textNode = titleElement->FirstChild()->ToText(); + title = textNode->Value(); + printf( "Name of play (2): %s\n", title ); + + return doc.ErrorID(); +} + + int main( int /*argc*/, const char ** /*argv*/ ) { #if defined( _MSC_VER ) && defined( DEBUG ) @@ -100,31 +145,11 @@ int main( int /*argc*/, const char ** /*argv*/ ) #pragma warning ( pop ) #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" ); + XMLTest( "Example-1", 0, example_1() ); + XMLTest( "Example-2", 0, example_2() ); + XMLTest( "Example-3", 0, example_3() ); - // 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 ); - } + /* ------ Example 2: Lookup information. ---- */ { static const char* test[] = { "", From c8678e2fcc69f7871e6c7384865ced9bdada8834 Mon Sep 17 00:00:00 2001 From: "Lee Thomason (grinliz)" Date: Wed, 4 Apr 2012 12:39:53 -0700 Subject: [PATCH 3/3] upped the version --- dox | 2 +- tinyxml2.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dox b/dox index 9568fa9..3a18853 100755 --- a/dox +++ b/dox @@ -32,7 +32,7 @@ PROJECT_NAME = "TinyXML-2" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 0.9.2 +PROJECT_NUMBER = 0.9.3 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer diff --git a/tinyxml2.h b/tinyxml2.h index 121fe03..bf00964 100644 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -96,7 +96,7 @@ distribution. static const int TIXML2_MAJOR_VERSION = 0; static const int TIXML2_MINOR_VERSION = 9; -static const int TIXML2_PATCH_VERSION = 2; +static const int TIXML2_PATCH_VERSION = 3; namespace tinyxml2 {