1*7485b225SElliott Hughes<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2*7485b225SElliott Hughes<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"> 3*7485b225SElliott Hughes<head> 4*7485b225SElliott Hughes<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> 5*7485b225SElliott Hughes<meta http-equiv="X-UA-Compatible" content="IE=11"/> 6*7485b225SElliott Hughes<meta name="generator" content="Doxygen 1.10.0"/> 7*7485b225SElliott Hughes<meta name="viewport" content="width=device-width, initial-scale=1"/> 8*7485b225SElliott Hughes<title>TinyXML-2: Read attributes and text information.</title> 9*7485b225SElliott Hughes<link href="tabs.css" rel="stylesheet" type="text/css"/> 10*7485b225SElliott Hughes<script type="text/javascript" src="jquery.js"></script> 11*7485b225SElliott Hughes<script type="text/javascript" src="dynsections.js"></script> 12*7485b225SElliott Hughes<script type="text/javascript" src="clipboard.js"></script> 13*7485b225SElliott Hughes<script type="text/javascript" src="cookie.js"></script> 14*7485b225SElliott Hughes<link href="search/search.css" rel="stylesheet" type="text/css"/> 15*7485b225SElliott Hughes<script type="text/javascript" src="search/searchdata.js"></script> 16*7485b225SElliott Hughes<script type="text/javascript" src="search/search.js"></script> 17*7485b225SElliott Hughes<link href="doxygen.css" rel="stylesheet" type="text/css" /> 18*7485b225SElliott Hughes</head> 19*7485b225SElliott Hughes<body> 20*7485b225SElliott Hughes<div id="top"><!-- do not remove this div, it is closed by doxygen! --> 21*7485b225SElliott Hughes<div id="titlearea"> 22*7485b225SElliott Hughes<table cellspacing="0" cellpadding="0"> 23*7485b225SElliott Hughes <tbody> 24*7485b225SElliott Hughes <tr id="projectrow"> 25*7485b225SElliott Hughes <td id="projectalign"> 26*7485b225SElliott Hughes <div id="projectname">TinyXML-2<span id="projectnumber"> 10.0.0</span> 27*7485b225SElliott Hughes </div> 28*7485b225SElliott Hughes </td> 29*7485b225SElliott Hughes </tr> 30*7485b225SElliott Hughes </tbody> 31*7485b225SElliott Hughes</table> 32*7485b225SElliott Hughes</div> 33*7485b225SElliott Hughes<!-- end header part --> 34*7485b225SElliott Hughes<!-- Generated by Doxygen 1.10.0 --> 35*7485b225SElliott Hughes<script type="text/javascript"> 36*7485b225SElliott Hughes/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ 37*7485b225SElliott Hughesvar searchBox = new SearchBox("searchBox", "search/",'.html'); 38*7485b225SElliott Hughes/* @license-end */ 39*7485b225SElliott Hughes</script> 40*7485b225SElliott Hughes<script type="text/javascript" src="menudata.js"></script> 41*7485b225SElliott Hughes<script type="text/javascript" src="menu.js"></script> 42*7485b225SElliott Hughes<script type="text/javascript"> 43*7485b225SElliott Hughes/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ 44*7485b225SElliott Hughes$(function() { 45*7485b225SElliott Hughes initMenu('',true,false,'search.php','Search'); 46*7485b225SElliott Hughes $(function() { init_search(); }); 47*7485b225SElliott Hughes}); 48*7485b225SElliott Hughes/* @license-end */ 49*7485b225SElliott Hughes</script> 50*7485b225SElliott Hughes<div id="main-nav"></div> 51*7485b225SElliott Hughes<!-- window showing the filter options --> 52*7485b225SElliott Hughes<div id="MSearchSelectWindow" 53*7485b225SElliott Hughes onmouseover="return searchBox.OnSearchSelectShow()" 54*7485b225SElliott Hughes onmouseout="return searchBox.OnSearchSelectHide()" 55*7485b225SElliott Hughes onkeydown="return searchBox.OnSearchSelectKey(event)"> 56*7485b225SElliott Hughes</div> 57*7485b225SElliott Hughes 58*7485b225SElliott Hughes<!-- iframe showing the search results (closed by default) --> 59*7485b225SElliott Hughes<div id="MSearchResultsWindow"> 60*7485b225SElliott Hughes<div id="MSearchResults"> 61*7485b225SElliott Hughes<div class="SRPage"> 62*7485b225SElliott Hughes<div id="SRIndex"> 63*7485b225SElliott Hughes<div id="SRResults"></div> 64*7485b225SElliott Hughes<div class="SRStatus" id="Loading">Loading...</div> 65*7485b225SElliott Hughes<div class="SRStatus" id="Searching">Searching...</div> 66*7485b225SElliott Hughes<div class="SRStatus" id="NoMatches">No Matches</div> 67*7485b225SElliott Hughes</div> 68*7485b225SElliott Hughes</div> 69*7485b225SElliott Hughes</div> 70*7485b225SElliott Hughes</div> 71*7485b225SElliott Hughes 72*7485b225SElliott Hughes</div><!-- top --> 73*7485b225SElliott Hughes<div><div class="header"> 74*7485b225SElliott Hughes <div class="headertitle"><div class="title">Read attributes and text information.</div></div> 75*7485b225SElliott Hughes</div><!--header--> 76*7485b225SElliott Hughes<div class="contents"> 77*7485b225SElliott Hughes<div class="textblock"><p></p> 78*7485b225SElliott Hughes<p>There are fundamentally 2 ways of writing a key-value pair into an XML file. (Something that's always annoyed me about XML.) Either by using attributes, or by writing the key name into an element and the value into the text node wrapped by the element. Both approaches are illustrated in this example, which shows two ways to encode the value "2" into the key "v":</p> 79*7485b225SElliott Hughes<div class="fragment"><div class="line"><span class="keywordtype">bool</span> example_4()</div> 80*7485b225SElliott Hughes<div class="line">{</div> 81*7485b225SElliott Hughes<div class="line"> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* xml =</div> 82*7485b225SElliott Hughes<div class="line"> <span class="stringliteral">"<information>"</span></div> 83*7485b225SElliott Hughes<div class="line"> <span class="stringliteral">" <attributeApproach v='2' />"</span></div> 84*7485b225SElliott Hughes<div class="line"> <span class="stringliteral">" <textApproach>"</span></div> 85*7485b225SElliott Hughes<div class="line"> <span class="stringliteral">" <v>2</v>"</span></div> 86*7485b225SElliott Hughes<div class="line"> <span class="stringliteral">" </textApproach>"</span></div> 87*7485b225SElliott Hughes<div class="line"> <span class="stringliteral">"</information>"</span>;</div> 88*7485b225SElliott Hughes</div><!-- fragment --><p> TinyXML-2 has accessors for both approaches.</p> 89*7485b225SElliott Hughes<p>When using an attribute, you navigate to the XMLElement with that attribute and use the QueryIntAttribute() group of methods. (Also QueryFloatAttribute(), etc.)</p> 90*7485b225SElliott Hughes<div class="fragment"><div class="line"> XMLElement* attributeApproachElement = doc.FirstChildElement()->FirstChildElement( <span class="stringliteral">"attributeApproach"</span> );</div> 91*7485b225SElliott Hughes<div class="line"> attributeApproachElement->QueryIntAttribute( <span class="stringliteral">"v"</span>, &v0 );</div> 92*7485b225SElliott Hughes</div><!-- fragment --><p> When using the text approach, you need to navigate down one more step to the XMLElement that contains the text. Note the extra FirstChildElement( "v" ) in the code below. The value of the text can then be safely queried with the QueryIntText() group of methods. (Also QueryFloatText(), etc.)</p> 93*7485b225SElliott Hughes<div class="fragment"><div class="line"> XMLElement* textApproachElement = doc.FirstChildElement()->FirstChildElement( <span class="stringliteral">"textApproach"</span> );</div> 94*7485b225SElliott Hughes<div class="line"> textApproachElement->FirstChildElement( <span class="stringliteral">"v"</span> )->QueryIntText( &v1 );</div> 95*7485b225SElliott Hughes</div><!-- fragment --></div></div><!-- contents --> 96*7485b225SElliott Hughes</div><!-- PageDoc --> 97*7485b225SElliott Hughes<!-- start footer part --> 98*7485b225SElliott Hughes<hr class="footer"/><address class="footer"><small> 99*7485b225SElliott HughesGenerated on Sat Dec 30 2023 18:02:35 for TinyXML-2 by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.10.0 100*7485b225SElliott Hughes</small></address> 101*7485b225SElliott Hughes</body> 102*7485b225SElliott Hughes</html> 103