update the docs
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||||
<meta name="generator" content="Doxygen 1.8.13"/>
|
||||
<meta name="generator" content="Doxygen 1.8.18"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>TinyXML-2: Get information out of XML</title>
|
||||
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
||||
@@ -22,7 +22,7 @@
|
||||
<tr style="height: 56px;">
|
||||
<td id="projectalign" style="padding-left: 0.5em;">
|
||||
<div id="projectname">TinyXML-2
|
||||
 <span id="projectnumber">7.0.0</span>
|
||||
 <span id="projectnumber">8.0.0</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -30,18 +30,21 @@
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.8.13 -->
|
||||
<!-- Generated by Doxygen 1.8.18 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
/* @license-end */
|
||||
</script>
|
||||
<script type="text/javascript" src="menudata.js"></script>
|
||||
<script type="text/javascript" src="menu.js"></script>
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||||
$(function() {
|
||||
initMenu('',true,false,'search.php','Search');
|
||||
$(document).ready(function() { init_search(); });
|
||||
});
|
||||
</script>
|
||||
/* @license-end */</script>
|
||||
<div id="main-nav"></div>
|
||||
<!-- window showing the filter options -->
|
||||
<div id="MSearchSelectWindow"
|
||||
@@ -58,15 +61,22 @@ $(function() {
|
||||
</div>
|
||||
|
||||
</div><!-- top -->
|
||||
<div class="header">
|
||||
<div class="PageDoc"><div class="header">
|
||||
<div class="headertitle">
|
||||
<div class="title">Get information out of XML </div> </div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
<div class="textblock"> In this example, we navigate a simple XML file, and read some interesting text. Note that this example doesn't use error checking; working code should check for null pointers when walking an XML tree, or use XMLHandle.</p>
|
||||
<div class="textblock"><p> In this example, we navigate a simple XML file, and read some interesting text. Note that this example doesn't use error checking; working code should check for null pointers when walking an XML tree, or use XMLHandle.</p>
|
||||
<p>(The XML is an excerpt from "dream.xml").</p>
|
||||
<p><div class="fragment"><div class="line"><span class="keywordtype">int</span> example_3()</div><div class="line">{</div><div class="line"> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* xml =</div><div class="line"> <span class="stringliteral">"<?xml version=\"1.0\"?>"</span></div><div class="line"> <span class="stringliteral">"<!DOCTYPE PLAY SYSTEM \"play.dtd\">"</span></div><div class="line"> <span class="stringliteral">"<PLAY>"</span></div><div class="line"> <span class="stringliteral">"<TITLE>A Midsummer Night's Dream</TITLE>"</span></div><div class="line"> <span class="stringliteral">"</PLAY>"</span>;</div></div><!-- fragment --></p>
|
||||
<p>The structure of the XML file is:</p>
|
||||
<div class="fragment"><div class="line"><span class="keywordtype">int</span> example_3()</div>
|
||||
<div class="line">{</div>
|
||||
<div class="line"> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* xml =</div>
|
||||
<div class="line"> <span class="stringliteral">"<?xml version=\"1.0\"?>"</span></div>
|
||||
<div class="line"> <span class="stringliteral">"<!DOCTYPE PLAY SYSTEM \"play.dtd\">"</span></div>
|
||||
<div class="line"> <span class="stringliteral">"<PLAY>"</span></div>
|
||||
<div class="line"> <span class="stringliteral">"<TITLE>A Midsummer Night's Dream</TITLE>"</span></div>
|
||||
<div class="line"> <span class="stringliteral">"</PLAY>"</span>;</div>
|
||||
</div><!-- fragment --><p>The structure of the XML file is:</p>
|
||||
<ul>
|
||||
<li>
|
||||
(declaration) </li>
|
||||
@@ -85,20 +95,29 @@ Text "A Midsummer Night's Dream" </li>
|
||||
</ul>
|
||||
<p>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.</p>
|
||||
<p>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.</p>
|
||||
<p><div class="fragment"><div class="line"></div><div class="line"> XMLDocument doc;</div><div class="line"> doc.Parse( xml );</div><div class="line"></div><div class="line"> XMLElement* titleElement = doc.FirstChildElement( <span class="stringliteral">"PLAY"</span> )->FirstChildElement( <span class="stringliteral">"TITLE"</span> );</div></div><!-- fragment --></p>
|
||||
<p>We can then use the convenience function GetText() to get the title of the play.</p>
|
||||
<p><div class="fragment"><div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span>* title = titleElement->GetText();</div><div class="line"> printf( <span class="stringliteral">"Name of play (1): %s\n"</span>, title );</div></div><!-- fragment --></p>
|
||||
<p>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.</p>
|
||||
<div class="fragment"><div class="line"> </div>
|
||||
<div class="line"> XMLDocument doc;</div>
|
||||
<div class="line"> doc.Parse( xml );</div>
|
||||
<div class="line"> </div>
|
||||
<div class="line"> XMLElement* titleElement = doc.FirstChildElement( <span class="stringliteral">"PLAY"</span> )->FirstChildElement( <span class="stringliteral">"TITLE"</span> );</div>
|
||||
</div><!-- fragment --><p>We can then use the convenience function GetText() to get the title of the play.</p>
|
||||
<div class="fragment"><div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span>* title = titleElement->GetText();</div>
|
||||
<div class="line"> printf( <span class="stringliteral">"Name of play (1): %s\n"</span>, title );</div>
|
||||
</div><!-- fragment --><p>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.</p>
|
||||
<pre class="fragment">Consider: A Midsummer Night's <b>Dream</b>
|
||||
</pre><p>It is more correct to actually query the Text Node if in doubt:</p>
|
||||
<p><div class="fragment"><div class="line"></div><div class="line"> XMLText* textNode = titleElement->FirstChild()->ToText();</div><div class="line"> title = textNode->Value();</div><div class="line"> printf( <span class="stringliteral">"Name of play (2): %s\n"</span>, title );</div></div><!-- fragment --></p>
|
||||
<p>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. </p>
|
||||
<div class="fragment"><div class="line"> </div>
|
||||
<div class="line"> XMLText* textNode = titleElement->FirstChild()->ToText();</div>
|
||||
<div class="line"> title = textNode->Value();</div>
|
||||
<div class="line"> printf( <span class="stringliteral">"Name of play (2): %s\n"</span>, title );</div>
|
||||
</div><!-- fragment --><p>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. </p>
|
||||
</div></div><!-- contents -->
|
||||
</div><!-- PageDoc -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
Generated on Tue Nov 6 2018 09:38:26 for TinyXML-2 by  <a href="http://www.doxygen.org/index.html">
|
||||
Generated on Sat Jun 13 2020 19:01:40 for TinyXML-2 by  <a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
||||
</a> 1.8.13
|
||||
</a> 1.8.18
|
||||
</small></address>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user