blob: 5f8d3918038259c4a79b849f537ee68cbc332157 [file] [log] [blame]
Lee Thomasonfc896702020-06-13 19:02:58 -07001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Lee Thomasoncf100692017-12-10 20:03:39 -08002<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<meta http-equiv="X-UA-Compatible" content="IE=9"/>
Lee Thomason32913902021-05-15 20:28:24 -07006<meta name="generator" content="Doxygen 1.9.1"/>
Lee Thomasoncf100692017-12-10 20:03:39 -08007<meta name="viewport" content="width=device-width, initial-scale=1"/>
8<title>TinyXML-2: Read attributes and text information.</title>
9<link href="tabs.css" rel="stylesheet" type="text/css"/>
10<script type="text/javascript" src="jquery.js"></script>
11<script type="text/javascript" src="dynsections.js"></script>
12<link href="search/search.css" rel="stylesheet" type="text/css"/>
13<script type="text/javascript" src="search/searchdata.js"></script>
14<script type="text/javascript" src="search/search.js"></script>
15<link href="doxygen.css" rel="stylesheet" type="text/css" />
16</head>
17<body>
18<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
19<div id="titlearea">
20<table cellspacing="0" cellpadding="0">
21 <tbody>
22 <tr style="height: 56px;">
23 <td id="projectalign" style="padding-left: 0.5em;">
24 <div id="projectname">TinyXML-2
Lee Thomason1dee28e2021-06-06 17:10:24 -070025 &#160;<span id="projectnumber">9.0.0</span>
Lee Thomasoncf100692017-12-10 20:03:39 -080026 </div>
27 </td>
28 </tr>
29 </tbody>
30</table>
31</div>
32<!-- end header part -->
Lee Thomason32913902021-05-15 20:28:24 -070033<!-- Generated by Doxygen 1.9.1 -->
Lee Thomasoncf100692017-12-10 20:03:39 -080034<script type="text/javascript">
Lee Thomasonfc896702020-06-13 19:02:58 -070035/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
Lee Thomason32913902021-05-15 20:28:24 -070036var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
Lee Thomasonfc896702020-06-13 19:02:58 -070037/* @license-end */
Lee Thomasoncf100692017-12-10 20:03:39 -080038</script>
39<script type="text/javascript" src="menudata.js"></script>
40<script type="text/javascript" src="menu.js"></script>
41<script type="text/javascript">
Lee Thomasonfc896702020-06-13 19:02:58 -070042/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
Lee Thomasoncf100692017-12-10 20:03:39 -080043$(function() {
44 initMenu('',true,false,'search.php','Search');
45 $(document).ready(function() { init_search(); });
46});
Lee Thomasonfc896702020-06-13 19:02:58 -070047/* @license-end */</script>
Lee Thomasoncf100692017-12-10 20:03:39 -080048<div id="main-nav"></div>
49<!-- window showing the filter options -->
50<div id="MSearchSelectWindow"
51 onmouseover="return searchBox.OnSearchSelectShow()"
52 onmouseout="return searchBox.OnSearchSelectHide()"
53 onkeydown="return searchBox.OnSearchSelectKey(event)">
54</div>
55
56<!-- iframe showing the search results (closed by default) -->
57<div id="MSearchResultsWindow">
58<iframe src="javascript:void(0)" frameborder="0"
59 name="MSearchResults" id="MSearchResults">
60</iframe>
61</div>
62
63</div><!-- top -->
Lee Thomasonfc896702020-06-13 19:02:58 -070064<div class="PageDoc"><div class="header">
Lee Thomasoncf100692017-12-10 20:03:39 -080065 <div class="headertitle">
66<div class="title">Read attributes and text information. </div> </div>
67</div><!--header-->
68<div class="contents">
Lee Thomasonfc896702020-06-13 19:02:58 -070069<div class="textblock"><p></p>
70<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>
71<div class="fragment"><div class="line"><span class="keywordtype">bool</span> example_4()</div>
72<div class="line">{</div>
73<div class="line"> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* xml =</div>
74<div class="line"> <span class="stringliteral">&quot;&lt;information&gt;&quot;</span></div>
75<div class="line"> <span class="stringliteral">&quot; &lt;attributeApproach v=&#39;2&#39; /&gt;&quot;</span></div>
76<div class="line"> <span class="stringliteral">&quot; &lt;textApproach&gt;&quot;</span></div>
77<div class="line"> <span class="stringliteral">&quot; &lt;v&gt;2&lt;/v&gt;&quot;</span></div>
78<div class="line"> <span class="stringliteral">&quot; &lt;/textApproach&gt;&quot;</span></div>
79<div class="line"> <span class="stringliteral">&quot;&lt;/information&gt;&quot;</span>;</div>
Lee Thomason32913902021-05-15 20:28:24 -070080</div><!-- fragment --><p> TinyXML-2 has accessors for both approaches.</p>
Lee Thomasoncf100692017-12-10 20:03:39 -080081<p>When using an attribute, you navigate to the XMLElement with that attribute and use the QueryIntAttribute() group of methods. (Also QueryFloatAttribute(), etc.)</p>
Lee Thomasonfc896702020-06-13 19:02:58 -070082<div class="fragment"><div class="line"> XMLElement* attributeApproachElement = doc.FirstChildElement()-&gt;FirstChildElement( <span class="stringliteral">&quot;attributeApproach&quot;</span> );</div>
83<div class="line"> attributeApproachElement-&gt;QueryIntAttribute( <span class="stringliteral">&quot;v&quot;</span>, &amp;v0 );</div>
Lee Thomason32913902021-05-15 20:28:24 -070084</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>
Lee Thomasonfc896702020-06-13 19:02:58 -070085<div class="fragment"><div class="line"> XMLElement* textApproachElement = doc.FirstChildElement()-&gt;FirstChildElement( <span class="stringliteral">&quot;textApproach&quot;</span> );</div>
86<div class="line"> textApproachElement-&gt;FirstChildElement( <span class="stringliteral">&quot;v&quot;</span> )-&gt;QueryIntText( &amp;v1 );</div>
Lee Thomason32913902021-05-15 20:28:24 -070087</div><!-- fragment --></div></div><!-- contents -->
Lee Thomasonfc896702020-06-13 19:02:58 -070088</div><!-- PageDoc -->
Lee Thomasoncf100692017-12-10 20:03:39 -080089<!-- start footer part -->
90<hr class="footer"/><address class="footer"><small>
Lee Thomason1dee28e2021-06-06 17:10:24 -070091Generated on Sun Jun 6 2021 17:10:05 for TinyXML-2 by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
Lee Thomasoncf100692017-12-10 20:03:39 -080092</small></address>
93</body>
94</html>