diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:05:53 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:05:53 +0200 |
commit | 618dfb51d93898632830f1b87443d3f748780871 (patch) | |
tree | bac520a2e261154f8d35b0cb8aa345f5ab373811 /shared/tinyxml/docs/tutorial0.html | |
parent | 3.4 (diff) | |
download | FreeFileSync-618dfb51d93898632830f1b87443d3f748780871.tar.gz FreeFileSync-618dfb51d93898632830f1b87443d3f748780871.tar.bz2 FreeFileSync-618dfb51d93898632830f1b87443d3f748780871.zip |
3.5
Diffstat (limited to 'shared/tinyxml/docs/tutorial0.html')
-rw-r--r-- | shared/tinyxml/docs/tutorial0.html | 291 |
1 files changed, 145 insertions, 146 deletions
diff --git a/shared/tinyxml/docs/tutorial0.html b/shared/tinyxml/docs/tutorial0.html index d5d19cab..f974f859 100644 --- a/shared/tinyxml/docs/tutorial0.html +++ b/shared/tinyxml/docs/tutorial0.html @@ -1,33 +1,41 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>TinyXml: TinyXML Tutorial</title> -<link href="doxygen.css" rel="stylesheet" type="text/css"> -<link href="tabs.css" rel="stylesheet" type="text/css"> -</head><body> -<!-- Generated by Doxygen 1.4.7 --> -<div class="tabs"> - <ul> - <li><a href="index.html"><span>Main Page</span></a></li> - <li><a href="annotated.html"><span>Classes</span></a></li> - <li><a href="files.html"><span>Files</span></a></li> - <li><a href="pages.html"><span>Related Pages</span></a></li> - </ul></div> -<div class="nav"> -<a class="el" href="index.html">index</a></div> -<h1><a class="anchor" name="tutorial0">TinyXML Tutorial</a></h1><h1>What is this? </h1> -<p> -This tutorial has a few tips and suggestions on how to use TinyXML effectively.<p> -I've also tried to include some C++ tips like how to convert strings to integers and vice versa. This isn't anything to do with TinyXML itself, but it may helpful for your project so I've put it in anyway.<p> -If you don't know basic C++ concepts this tutorial won't be useful. Likewise if you don't know what a DOM is, look elsewhere first.<p> +<link href="tabs.css" rel="stylesheet" type="text/css"/> +<link href="doxygen.css" rel="stylesheet" type="text/css"/> +</head> +<body> +<!-- Generated by Doxygen 1.6.2 --> +<div class="navigation" id="top"> + <div class="tabs"> + <ul> + <li><a href="index.html"><span>Main Page</span></a></li> + <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> + <li><a href="annotated.html"><span>Classes</span></a></li> + <li><a href="files.html"><span>Files</span></a></li> + </ul> + </div> + <div class="navpath"><a class="el" href="index.html">index</a> + </div> +</div> +<div class="contents"> + + +<h1><a class="anchor" id="tutorial0">TinyXML Tutorial </a></h1><h1>What is this? </h1> +<p>This tutorial has a few tips and suggestions on how to use TinyXML effectively.</p> +<p>I've also tried to include some C++ tips like how to convert strings to integers and vice versa. This isn't anything to do with TinyXML itself, but it may helpful for your project so I've put it in anyway.</p> +<p>If you don't know basic C++ concepts this tutorial won't be useful. Likewise if you don't know what a DOM is, look elsewhere first.</p> <h1>Before we start </h1> -<p> -Some example XML datasets/files will be used.<p> -example1.xml:<p> -<div class="fragment"><pre class="fragment"><?xml version="1.0" ?> +<p>Some example XML datasets/files will be used.</p> +<p>example1.xml:</p> +<div class="fragment"><pre class="fragment"> +<?xml version="1.0" ?> <Hello>World</Hello> -</pre></div><p> -example2.xml:<p> -<div class="fragment"><pre class="fragment"><?xml version="1.0" ?> +</pre></div><p>example2.xml:</p> +<div class="fragment"><pre class="fragment"> +<?xml version="1.0" ?> <poetry> <verse> Alas @@ -35,16 +43,16 @@ example2.xml:<p> Alas (again) </verse> </poetry> -</pre></div><p> -example3.xml:<p> -<div class="fragment"><pre class="fragment"><?xml version="1.0" ?> +</pre></div><p>example3.xml:</p> +<div class="fragment"><pre class="fragment"> +<?xml version="1.0" ?> <shapes> <circle name="int-based" x="20" y="30" r="50" /> <point name="float-based" x="3.5" y="52.1" /> </shapes> -</pre></div><p> -example4.xml<p> -<div class="fragment"><pre class="fragment"><?xml version="1.0" ?> +</pre></div><p>example4.xml</p> +<div class="fragment"><pre class="fragment"> +<?xml version="1.0" ?> <MyApp> <!-- Settings for MyApp --> <Messages> @@ -56,17 +64,15 @@ example4.xml<p> </Windows> <Connection ip="192.168.0.1" timeout="123.456000" /> </MyApp> -</pre></div><p> -<h1>Getting Started </h1> -<p> +</pre></div><h1>Getting Started </h1> <h2>Load XML from a file </h2> -<p> -The simplest way to load a file into a TinyXML DOM is:<p> -<div class="fragment"><pre class="fragment">TiXmlDocument doc( "demo.xml" ); +<p>The simplest way to load a file into a TinyXML DOM is:</p> +<div class="fragment"><pre class="fragment"> +TiXmlDocument doc( "demo.xml" ); doc.LoadFile(); -</pre></div><p> -A more real-world usage is shown below. This will load the file and display the contents to STDOUT:<p> -<div class="fragment"><pre class="fragment">// load the named file and dump its structure to STDOUT +</pre></div><p>A more real-world usage is shown below. This will load the file and display the contents to STDOUT:</p> +<div class="fragment"><pre class="fragment"> +// load the named file and dump its structure to STDOUT void dump_to_stdout(const char* pFilename) { TiXmlDocument doc(pFilename); @@ -81,29 +87,28 @@ void dump_to_stdout(const char* pFilename) printf("Failed to load file \"%s\"\n", pFilename); } } -</pre></div><p> -A simple demonstration of this function is to use a main like this:<p> -<div class="fragment"><pre class="fragment">int main(void) +</pre></div><p>A simple demonstration of this function is to use a main like this:</p> +<div class="fragment"><pre class="fragment"> +int main(void) { dump_to_stdout("example1.xml"); return 0; } -</pre></div><p> -Recall that Example 1 XML is:<p> -<div class="fragment"><pre class="fragment"><?xml version="1.0" ?> +</pre></div><p>Recall that Example 1 XML is:</p> +<div class="fragment"><pre class="fragment"> +<?xml version="1.0" ?> <Hello>World</Hello> -</pre></div><p> -Running the program with this XML will display this in the console/DOS window:<p> -<div class="fragment"><pre class="fragment">DOCUMENT +</pre></div><p>Running the program with this XML will display this in the console/DOS window:</p> +<div class="fragment"><pre class="fragment"> +DOCUMENT + DECLARATION + ELEMENT Hello + TEXT[World] -</pre></div><p> -The ``dump_to_stdout`` function is defined later in this tutorial and is useful if you want to understand recursive traversal of a DOM.<p> +</pre></div><p>The ``dump_to_stdout`` function is defined later in this tutorial and is useful if you want to understand recursive traversal of a DOM.</p> <h2>Building Documents Programatically </h2> -<p> -This is how to build Example 1 pragmatically:<p> -<div class="fragment"><pre class="fragment">void build_simple_doc( ) +<p>This is how to build Example 1 pragmatically:</p> +<div class="fragment"><pre class="fragment"> +void build_simple_doc( ) { // Make xml: <?xml ..><Hello>World</Hello> TiXmlDocument doc; @@ -115,19 +120,19 @@ This is how to build Example 1 pragmatically:<p> doc.LinkEndChild( element ); doc.SaveFile( "madeByHand.xml" ); } -</pre></div><p> -This can be loaded and displayed on the console with:<p> -<div class="fragment"><pre class="fragment">dump_to_stdout("madeByHand.xml"); // this func defined later in the tutorial -</pre></div><p> -and you'll see it is identical to Example 1:<p> -<div class="fragment"><pre class="fragment">madeByHand.xml: +</pre></div><p>This can be loaded and displayed on the console with:</p> +<div class="fragment"><pre class="fragment"> +dump_to_stdout("madeByHand.xml"); // this func defined later in the tutorial +</pre></div><p>and you'll see it is identical to Example 1:</p> +<div class="fragment"><pre class="fragment"> +madeByHand.xml: Document + Declaration + Element [Hello] + Text: [World] -</pre></div><p> -This code produces exactly the same XML DOM but it shows a different ordering to node creation and linking:<p> -<div class="fragment"><pre class="fragment">void write_simple_doc2( ) +</pre></div><p>This code produces exactly the same XML DOM but it shows a different ordering to node creation and linking:</p> +<div class="fragment"><pre class="fragment"> +void write_simple_doc2( ) { // same as write_simple_doc1 but add each node // as early as possible into the tree. @@ -144,29 +149,28 @@ This code produces exactly the same XML DOM but it shows a different ordering to doc.SaveFile( "madeByHand2.xml" ); } -</pre></div><p> -Both of these produce the same XML, namely:<p> -<div class="fragment"><pre class="fragment"><?xml version="1.0" ?> +</pre></div><p>Both of these produce the same XML, namely:</p> +<div class="fragment"><pre class="fragment"> +<?xml version="1.0" ?> <Hello>World</Hello> -</pre></div><p> -Or in structure form:<p> -<div class="fragment"><pre class="fragment">DOCUMENT +</pre></div><p>Or in structure form:</p> +<div class="fragment"><pre class="fragment"> +DOCUMENT + DECLARATION + ELEMENT Hello + TEXT[World] -</pre></div><p> -<h2>Attributes </h2> -<p> -Given an existing node, settings attributes is easy:<p> -<div class="fragment"><pre class="fragment">window = new TiXmlElement( "Demo" ); +</pre></div><h2>Attributes </h2> +<p>Given an existing node, settings attributes is easy:</p> +<div class="fragment"><pre class="fragment"> +window = new TiXmlElement( "Demo" ); window->SetAttribute("name", "Circle"); window->SetAttribute("x", 5); window->SetAttribute("y", 15); window->SetDoubleAttribute("radius", 3.14159); -</pre></div><p> -You can it also work with the <a class="el" href="classTiXmlAttribute.html">TiXmlAttribute</a> objects if you want.<p> -The following code shows one way (not the only way) to get all attributes of an element, print the name and string value, and if the value can be converted to an integer or double, print that value too:<p> -<div class="fragment"><pre class="fragment">// print all attributes of pElement. +</pre></div><p>You can it also work with the <a class="el" href="classTiXmlAttribute.html" title="An attribute is a name-value pair.">TiXmlAttribute</a> objects if you want.</p> +<p>The following code shows one way (not the only way) to get all attributes of an element, print the name and string value, and if the value can be converted to an integer or double, print that value too:</p> +<div class="fragment"><pre class="fragment"> +// print all attributes of pElement. // returns the number of attributes printed int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent) { @@ -190,14 +194,13 @@ int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent) } return i; } -</pre></div><p> -<h2>Writing a document to a file </h2> -<p> -Writing a pre-built DOM to a file is trivial:<p> -<div class="fragment"><pre class="fragment">doc.SaveFile( saveFilename ); -</pre></div><p> -Recall, for example, example 4:<p> -<div class="fragment"><pre class="fragment"><?xml version="1.0" ?> +</pre></div><h2>Writing a document to a file </h2> +<p>Writing a pre-built DOM to a file is trivial:</p> +<div class="fragment"><pre class="fragment"> +doc.SaveFile( saveFilename ); +</pre></div><p>Recall, for example, example 4:</p> +<div class="fragment"><pre class="fragment"> +<?xml version="1.0" ?> <MyApp> <!-- Settings for MyApp --> <Messages> @@ -209,9 +212,9 @@ Recall, for example, example 4:<p> </Windows> <Connection ip="192.168.0.1" timeout="123.456000" /> </MyApp> -</pre></div><p> -The following function builds this DOM and writes the file "appsettings.xml":<p> -<div class="fragment"><pre class="fragment">void write_app_settings_doc( ) +</pre></div><p>The following function builds this DOM and writes the file "appsettings.xml":</p> +<div class="fragment"><pre class="fragment"> +void write_app_settings_doc( ) { TiXmlDocument doc; TiXmlElement* msg; @@ -256,9 +259,9 @@ The following function builds this DOM and writes the file "appsettings.xml":<p> dump_to_stdout( &doc ); doc.SaveFile( "appsettings.xml" ); } -</pre></div><p> -The dump_to_stdout function will show this structure:<p> -<div class="fragment"><pre class="fragment">Document +</pre></div><p>The dump_to_stdout function will show this structure:</p> +<div class="fragment"><pre class="fragment"> +Document + Declaration + Element [MyApp] (No attributes) @@ -284,21 +287,18 @@ The dump_to_stdout function will show this structure:<p> + ip: value=[192.168.0.1] int=192 d=192.2 + timeout: value=[123.456000] int=123 d=123.5 2 attributes -</pre></div><p> -I was surprised that TinyXml, by default, writes the XML in what other APIs call a "pretty" format - it modifies the whitespace of text of elements that contain other nodes so that writing the tree includes an indication of nesting level.<p> -I haven't looked yet to see if there is a way to turn off indenting when writing a file - its bound to be easy.<p> -[Lee: It's easy in STL mode, just use cout << myDoc. Non-STL mode is always in "pretty" format. Adding a switch would be a nice feature and has been requested.]<p> +</pre></div><p>I was surprised that TinyXml, by default, writes the XML in what other APIs call a "pretty" format - it modifies the whitespace of text of elements that contain other nodes so that writing the tree includes an indication of nesting level.</p> +<p>I haven't looked yet to see if there is a way to turn off indenting when writing a file - its bound to be easy.</p> +<p>[Lee: It's easy in STL mode, just use cout << myDoc. Non-STL mode is always in "pretty" format. Adding a switch would be a nice feature and has been requested.]</p> <h1>XML to/from C++ objects </h1> -<p> <h2>Intro </h2> -<p> -This example assumes you're loading and saving your app settings in an XML file, e.g. something like example4.xml.<p> -There are a number of ways to do this. For example, look into the TinyBind project at <a href="http://sourceforge.net/projects/tinybind">http://sourceforge.net/projects/tinybind</a><p> -This section shows a plain-old approach to loading and saving a basic object structure using XML.<p> +<p>This example assumes you're loading and saving your app settings in an XML file, e.g. something like example4.xml.</p> +<p>There are a number of ways to do this. For example, look into the TinyBind project at <a href="http://sourceforge.net/projects/tinybind">http://sourceforge.net/projects/tinybind</a></p> +<p>This section shows a plain-old approach to loading and saving a basic object structure using XML.</p> <h2>Set up your object classes </h2> -<p> -Start off with some basic classes like these:<p> -<div class="fragment"><pre class="fragment">#include <string> +<p>Start off with some basic classes like these:</p> +<div class="fragment"><pre class="fragment"> +#include <string> #include <map> using namespace std; @@ -359,9 +359,9 @@ public: m_connection.timeout=123.456; } }; -</pre></div><p> -This is a basic main() that shows how to create a default settings object tree, save it and load it again:<p> -<div class="fragment"><pre class="fragment">int main(void) +</pre></div><p>This is a basic main() that shows how to create a default settings object tree, save it and load it again:</p> +<div class="fragment"><pre class="fragment"> +int main(void) { AppSettings settings; @@ -369,9 +369,9 @@ This is a basic main() that shows how to create a default settings object tree, settings.load("appsettings2.xml"); return 0; } -</pre></div><p> -The following main() shows creation, modification, saving and then loading of a settings structure:<p> -<div class="fragment"><pre class="fragment">int main(void) +</pre></div><p>The following main() shows creation, modification, saving and then loading of a settings structure:</p> +<div class="fragment"><pre class="fragment"> +int main(void) { // block: customise and save settings { @@ -399,16 +399,15 @@ The following main() shows creation, modification, saving and then loading of a } return 0; } -</pre></div><p> -When the save() and load() are completed (see below), running this main() displays on the console:<p> -<div class="fragment"><pre class="fragment">HitchHikerApp: Don't Panic +</pre></div><p>When the save() and load() are completed (see below), running this main() displays on the console:</p> +<div class="fragment"><pre class="fragment"> +HitchHikerApp: Don't Panic HitchHikerApp: Show window 'BookFrame' at 15,25 (300 x 100) HitchHikerApp: Thanks for all the fish -</pre></div><p> -<h2>Encode C++ state as XML </h2> -<p> -There are lots of different ways to approach saving this to a file. Here's one:<p> -<div class="fragment"><pre class="fragment">void AppSettings::save(const char* pFilename) +</pre></div><h2>Encode C++ state as XML </h2> +<p>There are lots of different ways to approach saving this to a file. Here's one:</p> +<div class="fragment"><pre class="fragment"> +void AppSettings::save(const char* pFilename) { TiXmlDocument doc; TiXmlElement* msg; @@ -474,9 +473,9 @@ There are lots of different ways to approach saving this to a file. Here's one:< doc.SaveFile(pFilename); } -</pre></div><p> -Running this with the modified main produces this file:<p> -<div class="fragment"><pre class="fragment"><?xml version="1.0" ?> +</pre></div><p>Running this with the modified main produces this file:</p> +<div class="fragment"><pre class="fragment"> +<?xml version="1.0" ?> <HitchHikerApp> <!-- Settings for HitchHikerApp --> <Messages> @@ -488,11 +487,10 @@ Running this with the modified main produces this file:<p> </Windows> <Connection ip="192.168.0.77" timeout="42.000000" /> </HitchHikerApp> -</pre></div><p> -<h2>Decoding state from XML </h2> -<p> -As with encoding objects, there are a number of approaches to decoding XML into your own C++ object structure. The following approach uses TiXmlHandles.<p> -<div class="fragment"><pre class="fragment">void AppSettings::load(const char* pFilename) +</pre></div><h2>Decoding state from XML </h2> +<p>As with encoding objects, there are a number of approaches to decoding XML into your own C++ object structure. The following approach uses TiXmlHandles.</p> +<div class="fragment"><pre class="fragment"> +void AppSettings::load(const char* pFilename) { TiXmlDocument doc(pFilename); if (!doc.LoadFile()) return; @@ -558,11 +556,10 @@ As with encoding objects, there are a number of approaches to decoding XML into } } } -</pre></div><p> -<h1>Full listing for dump_to_stdout </h1> -<p> -Below is a copy-and-paste demo program for loading arbitrary XML files and dumping the structure to STDOUT using the recursive traversal listed above.<p> -<div class="fragment"><pre class="fragment">// tutorial demo program +</pre></div><h1>Full listing for dump_to_stdout </h1> +<p>Below is a copy-and-paste demo program for loading arbitrary XML files and dumping the structure to STDOUT using the recursive traversal listed above.</p> +<div class="fragment"><pre class="fragment"> +// tutorial demo program #include "stdafx.h" #include "tinyxml.h" @@ -627,11 +624,11 @@ void dump_to_stdout( TiXmlNode* pParent, unsigned int indent = 0 ) switch ( t ) { - case TiXmlNode::DOCUMENT: + case TiXmlNode::TINYXML_DOCUMENT: printf( "Document" ); break; - case TiXmlNode::ELEMENT: + case TiXmlNode::TINYXML_ELEMENT: printf( "Element [%s]", pParent->Value() ); num=dump_attribs_to_stdout(pParent->ToElement(), indent+1); switch(num) @@ -642,20 +639,20 @@ void dump_to_stdout( TiXmlNode* pParent, unsigned int indent = 0 ) } break; - case TiXmlNode::COMMENT: + case TiXmlNode::TINYXML_COMMENT: printf( "Comment: [%s]", pParent->Value()); break; - case TiXmlNode::UNKNOWN: + case TiXmlNode::TINYXML_UNKNOWN: printf( "Unknown" ); break; - case TiXmlNode::TEXT: + case TiXmlNode::TINYXML_TEXT: pText = pParent->ToText(); printf( "Text: [%s]", pText->Value() ); break; - case TiXmlNode::DECLARATION: + case TiXmlNode::TINYXML_DECLARATION: printf( "Declaration" ); break; default: @@ -695,9 +692,9 @@ int main(int argc, char* argv[]) } return 0; } -</pre></div><p> -Run this from the command line or a DOS window, e.g.:<p> -<div class="fragment"><pre class="fragment">C:\dev\tinyxml> Debug\tinyxml_1.exe example1.xml +</pre></div><p>Run this from the command line or a DOS window, e.g.:</p> +<div class="fragment"><pre class="fragment"> +C:\dev\tinyxml> Debug\tinyxml_1.exe example1.xml example1.xml: Document @@ -705,8 +702,8 @@ Document + Element [Hello] (No attributes) + Text: [World] -</pre></div><p> -<em> Authors and Changes <ul> +</pre></div><p><em> Authors and Changes </p> +<ul> <li> Written by Ellers, April, May, June 2005 </li> <li> @@ -714,8 +711,10 @@ Minor edits and integration into doc system, Lee Thomason September 2005 </li> <li> Updated by Ellers, October 2005 </li> </ul> -</em> <hr size="1"><address style="align: right;"><small>Generated on Sun May 6 15:41:23 2007 for TinyXml by +<p></em> </p> +</div> +<hr size="1"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> -<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address> +<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address> </body> </html> |