Lee Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 2 | <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 Thomason | 3291390 | 2021-05-15 20:28:24 -0700 | [diff] [blame] | 6 | <meta name="generator" content="Doxygen 1.9.1"/> |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 7 | <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 Thomason | 1dee28e | 2021-06-06 17:10:24 -0700 | [diff] [blame] | 25 |  <span id="projectnumber">9.0.0</span> |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 26 | </div> |
| 27 | </td> |
| 28 | </tr> |
| 29 | </tbody> |
| 30 | </table> |
| 31 | </div> |
| 32 | <!-- end header part --> |
Lee Thomason | 3291390 | 2021-05-15 20:28:24 -0700 | [diff] [blame] | 33 | <!-- Generated by Doxygen 1.9.1 --> |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 34 | <script type="text/javascript"> |
Lee Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 35 | /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ |
Lee Thomason | 3291390 | 2021-05-15 20:28:24 -0700 | [diff] [blame] | 36 | var searchBox = new SearchBox("searchBox", "search",false,'Search','.html'); |
Lee Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 37 | /* @license-end */ |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 38 | </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 Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 42 | /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 43 | $(function() { |
| 44 | initMenu('',true,false,'search.php','Search'); |
| 45 | $(document).ready(function() { init_search(); }); |
| 46 | }); |
Lee Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 47 | /* @license-end */</script> |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 48 | <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 Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 64 | <div class="PageDoc"><div class="header"> |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 65 | <div class="headertitle"> |
| 66 | <div class="title">Read attributes and text information. </div> </div> |
| 67 | </div><!--header--> |
| 68 | <div class="contents"> |
Lee Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 69 | <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">"<information>"</span></div> |
| 75 | <div class="line"> <span class="stringliteral">" <attributeApproach v='2' />"</span></div> |
| 76 | <div class="line"> <span class="stringliteral">" <textApproach>"</span></div> |
| 77 | <div class="line"> <span class="stringliteral">" <v>2</v>"</span></div> |
| 78 | <div class="line"> <span class="stringliteral">" </textApproach>"</span></div> |
| 79 | <div class="line"> <span class="stringliteral">"</information>"</span>;</div> |
Lee Thomason | 3291390 | 2021-05-15 20:28:24 -0700 | [diff] [blame] | 80 | </div><!-- fragment --><p> TinyXML-2 has accessors for both approaches.</p> |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 81 | <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 Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 82 | <div class="fragment"><div class="line"> XMLElement* attributeApproachElement = doc.FirstChildElement()->FirstChildElement( <span class="stringliteral">"attributeApproach"</span> );</div> |
| 83 | <div class="line"> attributeApproachElement->QueryIntAttribute( <span class="stringliteral">"v"</span>, &v0 );</div> |
Lee Thomason | 3291390 | 2021-05-15 20:28:24 -0700 | [diff] [blame] | 84 | </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 Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 85 | <div class="fragment"><div class="line"> XMLElement* textApproachElement = doc.FirstChildElement()->FirstChildElement( <span class="stringliteral">"textApproach"</span> );</div> |
| 86 | <div class="line"> textApproachElement->FirstChildElement( <span class="stringliteral">"v"</span> )->QueryIntText( &v1 );</div> |
Lee Thomason | 3291390 | 2021-05-15 20:28:24 -0700 | [diff] [blame] | 87 | </div><!-- fragment --></div></div><!-- contents --> |
Lee Thomason | fc89670 | 2020-06-13 19:02:58 -0700 | [diff] [blame] | 88 | </div><!-- PageDoc --> |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 89 | <!-- start footer part --> |
| 90 | <hr class="footer"/><address class="footer"><small> |
Lee Thomason | 1dee28e | 2021-06-06 17:10:24 -0700 | [diff] [blame] | 91 | Generated on Sun Jun 6 2021 17:10:05 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.9.1 |
Lee Thomason | cf10069 | 2017-12-10 20:03:39 -0800 | [diff] [blame] | 92 | </small></address> |
| 93 | </body> |
| 94 | </html> |