1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> 3<title>TinyXml: TiXmlElement Class Reference</title> 4<link href="doxygen.css" rel="stylesheet" type="text/css"> 5</head><body> 6<!-- Generated by Doxygen 1.4.4 --> 7<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a></div> 8<h1>TiXmlElement Class Reference</h1><!-- doxytag: class="TiXmlElement" --><!-- doxytag: inherits="TiXmlNode" -->The element is a container class. 9<a href="#_details">More...</a> 10<p> 11<code>#include <<a class="el" href="tinyxml_8h-source.html">tinyxml.h</a>></code> 12<p> 13<p>Inheritance diagram for TiXmlElement: 14<p><center><img src="classTiXmlElement.png" usemap="#TiXmlElement_map" border="0" alt=""></center> 15<map name="TiXmlElement_map"> 16<area href="classTiXmlNode.html" alt="TiXmlNode" shape="rect" coords="0,56,87,80"> 17<area href="classTiXmlBase.html" alt="TiXmlBase" shape="rect" coords="0,0,87,24"> 18</map> 19<a href="classTiXmlElement-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0"> 20<tr><td></td></tr> 21<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr> 22<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a0"></a><!-- doxytag: member="TiXmlElement::TiXmlElement" ref="a0" args="(const char *in_value)" --> 23 </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a0">TiXmlElement</a> (const char *in_value)</td></tr> 24 25<tr><td class="mdescLeft"> </td><td class="mdescRight">Construct an element. <br></td></tr> 26<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a1"></a><!-- doxytag: member="TiXmlElement::TiXmlElement" ref="a1" args="(const std::string &_value)" --> 27 </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a1">TiXmlElement</a> (const std::string &_value)</td></tr> 28 29<tr><td class="mdescLeft"> </td><td class="mdescRight">std::string constructor. <br></td></tr> 30<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a5"></a><!-- doxytag: member="TiXmlElement::Attribute" ref="a5" args="(const char *name) const " --> 31const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a5">Attribute</a> (const char *name) const </td></tr> 32 33<tr><td class="mdescLeft"> </td><td class="mdescRight">Given an attribute name, <a class="el" href="classTiXmlElement.html#a5">Attribute()</a> returns the value for the attribute of that name, or null if none exists. <br></td></tr> 34<tr><td class="memItemLeft" nowrap align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a6">Attribute</a> (const char *name, int *i) const </td></tr> 35 36<tr><td class="mdescLeft"> </td><td class="mdescRight">Given an attribute name, <a class="el" href="classTiXmlElement.html#a5">Attribute()</a> returns the value for the attribute of that name, or null if none exists. <a href="#a6"></a><br></td></tr> 37<tr><td class="memItemLeft" nowrap align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a7">Attribute</a> (const char *name, double *d) const </td></tr> 38 39<tr><td class="mdescLeft"> </td><td class="mdescRight">Given an attribute name, <a class="el" href="classTiXmlElement.html#a5">Attribute()</a> returns the value for the attribute of that name, or null if none exists. <a href="#a7"></a><br></td></tr> 40<tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a8">QueryIntAttribute</a> (const char *name, int *_value) const </td></tr> 41 42<tr><td class="mdescLeft"> </td><td class="mdescRight">QueryIntAttribute examines the attribute - it is an alternative to the <a class="el" href="classTiXmlElement.html#a5">Attribute()</a> method with richer error checking. <a href="#a8"></a><br></td></tr> 43<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a9"></a><!-- doxytag: member="TiXmlElement::QueryDoubleAttribute" ref="a9" args="(const char *name, double *_value) const " --> 44int </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a9">QueryDoubleAttribute</a> (const char *name, double *_value) const </td></tr> 45 46<tr><td class="mdescLeft"> </td><td class="mdescRight">QueryDoubleAttribute examines the attribute - see <a class="el" href="classTiXmlElement.html#a8">QueryIntAttribute()</a>. <br></td></tr> 47<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a10"></a><!-- doxytag: member="TiXmlElement::QueryFloatAttribute" ref="a10" args="(const char *name, float *_value) const " --> 48int </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a10">QueryFloatAttribute</a> (const char *name, float *_value) const </td></tr> 49 50<tr><td class="mdescLeft"> </td><td class="mdescRight">QueryFloatAttribute examines the attribute - see <a class="el" href="classTiXmlElement.html#a8">QueryIntAttribute()</a>. <br></td></tr> 51<tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a11">SetAttribute</a> (const char *name, const char *_value)</td></tr> 52 53<tr><td class="mdescLeft"> </td><td class="mdescRight">Sets an attribute of name to a given value. <a href="#a11"></a><br></td></tr> 54<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a17"></a><!-- doxytag: member="TiXmlElement::SetAttribute" ref="a17" args="(const std::string &name, const std::string &_value)" --> 55void </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a17">SetAttribute</a> (const std::string &name, const std::string &_value)</td></tr> 56 57<tr><td class="mdescLeft"> </td><td class="mdescRight">STL std::string form. STL std::string form. <br></td></tr> 58<tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a19">SetAttribute</a> (const char *name, int value)</td></tr> 59 60<tr><td class="mdescLeft"> </td><td class="mdescRight">Sets an attribute of name to a given value. <a href="#a19"></a><br></td></tr> 61<tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a20">SetDoubleAttribute</a> (const char *name, double value)</td></tr> 62 63<tr><td class="mdescLeft"> </td><td class="mdescRight">Sets an attribute of name to a given value. <a href="#a20"></a><br></td></tr> 64<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a21"></a><!-- doxytag: member="TiXmlElement::RemoveAttribute" ref="a21" args="(const char *name)" --> 65void </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a21">RemoveAttribute</a> (const char *name)</td></tr> 66 67<tr><td class="mdescLeft"> </td><td class="mdescRight">Deletes an attribute with the given name. <br></td></tr> 68<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a22"></a><!-- doxytag: member="TiXmlElement::RemoveAttribute" ref="a22" args="(const std::string &name)" --> 69void </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a22">RemoveAttribute</a> (const std::string &name)</td></tr> 70 71<tr><td class="mdescLeft"> </td><td class="mdescRight">STL std::string form. <br></td></tr> 72<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a23"></a><!-- doxytag: member="TiXmlElement::FirstAttribute" ref="a23" args="() const " --> 73const <a class="el" href="classTiXmlAttribute.html">TiXmlAttribute</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a23">FirstAttribute</a> () const </td></tr> 74 75<tr><td class="mdescLeft"> </td><td class="mdescRight">Access the first attribute in this element. <br></td></tr> 76<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a25"></a><!-- doxytag: member="TiXmlElement::LastAttribute" ref="a25" args="() const " --> 77const <a class="el" href="classTiXmlAttribute.html">TiXmlAttribute</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a25">LastAttribute</a> () const </td></tr> 78 79<tr><td class="mdescLeft"> </td><td class="mdescRight">Access the last attribute in this element. <br></td></tr> 80<tr><td class="memItemLeft" nowrap align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a27">GetText</a> () const </td></tr> 81 82<tr><td class="mdescLeft"> </td><td class="mdescRight">Convenience function for easy access to the text inside an element. <a href="#a27"></a><br></td></tr> 83<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a28"></a><!-- doxytag: member="TiXmlElement::Clone" ref="a28" args="() const " --> 84virtual <a class="el" href="classTiXmlNode.html">TiXmlNode</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a28">Clone</a> () const </td></tr> 85 86<tr><td class="mdescLeft"> </td><td class="mdescRight">Creates a new Element and returns it - the returned element is a copy. <br></td></tr> 87<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><a class="el" href="classTiXmlElement.html#a29">Print</a> (FILE *cfile, int depth) const </td></tr> 88 89<tr><td class="mdescLeft"> </td><td class="mdescRight">All TinyXml classes can print themselves to a filestream. <a href="#a29"></a><br></td></tr> 90</table> 91<hr><a name="_details"></a><h2>Detailed Description</h2> 92The element is a container class. 93<p> 94It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes. 95<p> 96<hr><h2>Member Function Documentation</h2> 97<a class="anchor" name="a7"></a><!-- doxytag: member="TiXmlElement::Attribute" ref="a7" args="(const char *name, double *d) const " --><p> 98<table class="mdTable" cellpadding="2" cellspacing="0"> 99 <tr> 100 <td class="mdRow"> 101 <table cellpadding="0" cellspacing="0" border="0"> 102 <tr> 103 <td class="md" nowrap valign="top">const char* TiXmlElement::Attribute </td> 104 <td class="md" valign="top">( </td> 105 <td class="md" nowrap valign="top">const char * </td> 106 <td class="mdname" nowrap> <em>name</em>, </td> 107 </tr> 108 <tr> 109 <td class="md" nowrap align="right"></td> 110 <td class="md"></td> 111 <td class="md" nowrap>double * </td> 112 <td class="mdname" nowrap> <em>d</em></td> 113 </tr> 114 <tr> 115 <td class="md"></td> 116 <td class="md">) </td> 117 <td class="md" colspan="2"> const</td> 118 </tr> 119 </table> 120 </td> 121 </tr> 122</table> 123<table cellspacing="5" cellpadding="0" border="0"> 124 <tr> 125 <td> 126 127 </td> 128 <td> 129 130<p> 131Given an attribute name, <a class="el" href="classTiXmlElement.html#a5">Attribute()</a> returns the value for the attribute of that name, or null if none exists. 132<p> 133If the attribute exists and can be converted to an double, the double value will be put in the return 'd', if 'd' is non-null. </td> 134 </tr> 135</table> 136<a class="anchor" name="a6"></a><!-- doxytag: member="TiXmlElement::Attribute" ref="a6" args="(const char *name, int *i) const " --><p> 137<table class="mdTable" cellpadding="2" cellspacing="0"> 138 <tr> 139 <td class="mdRow"> 140 <table cellpadding="0" cellspacing="0" border="0"> 141 <tr> 142 <td class="md" nowrap valign="top">const char* TiXmlElement::Attribute </td> 143 <td class="md" valign="top">( </td> 144 <td class="md" nowrap valign="top">const char * </td> 145 <td class="mdname" nowrap> <em>name</em>, </td> 146 </tr> 147 <tr> 148 <td class="md" nowrap align="right"></td> 149 <td class="md"></td> 150 <td class="md" nowrap>int * </td> 151 <td class="mdname" nowrap> <em>i</em></td> 152 </tr> 153 <tr> 154 <td class="md"></td> 155 <td class="md">) </td> 156 <td class="md" colspan="2"> const</td> 157 </tr> 158 </table> 159 </td> 160 </tr> 161</table> 162<table cellspacing="5" cellpadding="0" border="0"> 163 <tr> 164 <td> 165 166 </td> 167 <td> 168 169<p> 170Given an attribute name, <a class="el" href="classTiXmlElement.html#a5">Attribute()</a> returns the value for the attribute of that name, or null if none exists. 171<p> 172If the attribute exists and can be converted to an integer, the integer value will be put in the return 'i', if 'i' is non-null. </td> 173 </tr> 174</table> 175<a class="anchor" name="a27"></a><!-- doxytag: member="TiXmlElement::GetText" ref="a27" args="() const " --><p> 176<table class="mdTable" cellpadding="2" cellspacing="0"> 177 <tr> 178 <td class="mdRow"> 179 <table cellpadding="0" cellspacing="0" border="0"> 180 <tr> 181 <td class="md" nowrap valign="top">const char* TiXmlElement::GetText </td> 182 <td class="md" valign="top">( </td> 183 <td class="mdname1" valign="top" nowrap> </td> 184 <td class="md" valign="top"> ) </td> 185 <td class="md" nowrap> const</td> 186 </tr> 187 </table> 188 </td> 189 </tr> 190</table> 191<table cellspacing="5" cellpadding="0" border="0"> 192 <tr> 193 <td> 194 195 </td> 196 <td> 197 198<p> 199Convenience function for easy access to the text inside an element. 200<p> 201Although easy and concise, <a class="el" href="classTiXmlElement.html#a27">GetText()</a> is limited compared to getting the <a class="el" href="classTiXmlText.html">TiXmlText</a> child and accessing it directly.<p> 202If the first child of 'this' is a <a class="el" href="classTiXmlText.html">TiXmlText</a>, the <a class="el" href="classTiXmlElement.html#a27">GetText()</a> returs the character string of the Text node, else null is returned.<p> 203This is a convenient method for getting the text of simple contained text: <div class="fragment"><pre class="fragment"> <foo>This is text</foo> 204 const char* str = fooElement->GetText(); 205 </pre></div><p> 206'str' will be a pointer to "This is text".<p> 207Note that this function can be misleading. If the element foo was created from this XML: <div class="fragment"><pre class="fragment"> <foo><b>This is text</b></foo> 208 </pre></div><p> 209then the value of str would be null. The first child node isn't a text node, it is another element. From this XML: <div class="fragment"><pre class="fragment"> <foo>This is <b>text</b></foo> 210 </pre></div> <a class="el" href="classTiXmlElement.html#a27">GetText()</a> will return "This is ".<p> 211WARNING: <a class="el" href="classTiXmlElement.html#a27">GetText()</a> accesses a child node - don't become confused with the similarly named <a class="el" href="classTiXmlHandle.html#a17">TiXmlHandle::Text()</a> and <a class="el" href="classTiXmlNode.html#a70">TiXmlNode::ToText()</a> which are safe type casts on the referenced node. </td> 212 </tr> 213</table> 214<a class="anchor" name="a29"></a><!-- doxytag: member="TiXmlElement::Print" ref="a29" args="(FILE *cfile, int depth) const " --><p> 215<table class="mdTable" cellpadding="2" cellspacing="0"> 216 <tr> 217 <td class="mdRow"> 218 <table cellpadding="0" cellspacing="0" border="0"> 219 <tr> 220 <td class="md" nowrap valign="top">virtual void TiXmlElement::Print </td> 221 <td class="md" valign="top">( </td> 222 <td class="md" nowrap valign="top">FILE * </td> 223 <td class="mdname" nowrap> <em>cfile</em>, </td> 224 </tr> 225 <tr> 226 <td class="md" nowrap align="right"></td> 227 <td class="md"></td> 228 <td class="md" nowrap>int </td> 229 <td class="mdname" nowrap> <em>depth</em></td> 230 </tr> 231 <tr> 232 <td class="md"></td> 233 <td class="md">) </td> 234 <td class="md" colspan="2"> const<code> [virtual]</code></td> 235 </tr> 236 </table> 237 </td> 238 </tr> 239</table> 240<table cellspacing="5" cellpadding="0" border="0"> 241 <tr> 242 <td> 243 244 </td> 245 <td> 246 247<p> 248All TinyXml classes can print themselves to a filestream. 249<p> 250This is a formatted print, and will insert tabs and newlines.<p> 251(For an unformatted stream, use the << operator.) 252<p> 253Implements <a class="el" href="classTiXmlBase.html#a2">TiXmlBase</a>. </td> 254 </tr> 255</table> 256<a class="anchor" name="a8"></a><!-- doxytag: member="TiXmlElement::QueryIntAttribute" ref="a8" args="(const char *name, int *_value) const " --><p> 257<table class="mdTable" cellpadding="2" cellspacing="0"> 258 <tr> 259 <td class="mdRow"> 260 <table cellpadding="0" cellspacing="0" border="0"> 261 <tr> 262 <td class="md" nowrap valign="top">int TiXmlElement::QueryIntAttribute </td> 263 <td class="md" valign="top">( </td> 264 <td class="md" nowrap valign="top">const char * </td> 265 <td class="mdname" nowrap> <em>name</em>, </td> 266 </tr> 267 <tr> 268 <td class="md" nowrap align="right"></td> 269 <td class="md"></td> 270 <td class="md" nowrap>int * </td> 271 <td class="mdname" nowrap> <em>_value</em></td> 272 </tr> 273 <tr> 274 <td class="md"></td> 275 <td class="md">) </td> 276 <td class="md" colspan="2"> const</td> 277 </tr> 278 </table> 279 </td> 280 </tr> 281</table> 282<table cellspacing="5" cellpadding="0" border="0"> 283 <tr> 284 <td> 285 286 </td> 287 <td> 288 289<p> 290QueryIntAttribute examines the attribute - it is an alternative to the <a class="el" href="classTiXmlElement.html#a5">Attribute()</a> method with richer error checking. 291<p> 292If the attribute is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. If the attribute does not exist, then TIXML_NO_ATTRIBUTE is returned. </td> 293 </tr> 294</table> 295<a class="anchor" name="a19"></a><!-- doxytag: member="TiXmlElement::SetAttribute" ref="a19" args="(const char *name, int value)" --><p> 296<table class="mdTable" cellpadding="2" cellspacing="0"> 297 <tr> 298 <td class="mdRow"> 299 <table cellpadding="0" cellspacing="0" border="0"> 300 <tr> 301 <td class="md" nowrap valign="top">void TiXmlElement::SetAttribute </td> 302 <td class="md" valign="top">( </td> 303 <td class="md" nowrap valign="top">const char * </td> 304 <td class="mdname" nowrap> <em>name</em>, </td> 305 </tr> 306 <tr> 307 <td class="md" nowrap align="right"></td> 308 <td class="md"></td> 309 <td class="md" nowrap>int </td> 310 <td class="mdname" nowrap> <em>value</em></td> 311 </tr> 312 <tr> 313 <td class="md"></td> 314 <td class="md">) </td> 315 <td class="md" colspan="2"></td> 316 </tr> 317 </table> 318 </td> 319 </tr> 320</table> 321<table cellspacing="5" cellpadding="0" border="0"> 322 <tr> 323 <td> 324 325 </td> 326 <td> 327 328<p> 329Sets an attribute of name to a given value. 330<p> 331The attribute will be created if it does not exist, or changed if it does. </td> 332 </tr> 333</table> 334<a class="anchor" name="a11"></a><!-- doxytag: member="TiXmlElement::SetAttribute" ref="a11" args="(const char *name, const char *_value)" --><p> 335<table class="mdTable" cellpadding="2" cellspacing="0"> 336 <tr> 337 <td class="mdRow"> 338 <table cellpadding="0" cellspacing="0" border="0"> 339 <tr> 340 <td class="md" nowrap valign="top">void TiXmlElement::SetAttribute </td> 341 <td class="md" valign="top">( </td> 342 <td class="md" nowrap valign="top">const char * </td> 343 <td class="mdname" nowrap> <em>name</em>, </td> 344 </tr> 345 <tr> 346 <td class="md" nowrap align="right"></td> 347 <td class="md"></td> 348 <td class="md" nowrap>const char * </td> 349 <td class="mdname" nowrap> <em>_value</em></td> 350 </tr> 351 <tr> 352 <td class="md"></td> 353 <td class="md">) </td> 354 <td class="md" colspan="2"></td> 355 </tr> 356 </table> 357 </td> 358 </tr> 359</table> 360<table cellspacing="5" cellpadding="0" border="0"> 361 <tr> 362 <td> 363 364 </td> 365 <td> 366 367<p> 368Sets an attribute of name to a given value. 369<p> 370The attribute will be created if it does not exist, or changed if it does. </td> 371 </tr> 372</table> 373<a class="anchor" name="a20"></a><!-- doxytag: member="TiXmlElement::SetDoubleAttribute" ref="a20" args="(const char *name, double value)" --><p> 374<table class="mdTable" cellpadding="2" cellspacing="0"> 375 <tr> 376 <td class="mdRow"> 377 <table cellpadding="0" cellspacing="0" border="0"> 378 <tr> 379 <td class="md" nowrap valign="top">void TiXmlElement::SetDoubleAttribute </td> 380 <td class="md" valign="top">( </td> 381 <td class="md" nowrap valign="top">const char * </td> 382 <td class="mdname" nowrap> <em>name</em>, </td> 383 </tr> 384 <tr> 385 <td class="md" nowrap align="right"></td> 386 <td class="md"></td> 387 <td class="md" nowrap>double </td> 388 <td class="mdname" nowrap> <em>value</em></td> 389 </tr> 390 <tr> 391 <td class="md"></td> 392 <td class="md">) </td> 393 <td class="md" colspan="2"></td> 394 </tr> 395 </table> 396 </td> 397 </tr> 398</table> 399<table cellspacing="5" cellpadding="0" border="0"> 400 <tr> 401 <td> 402 403 </td> 404 <td> 405 406<p> 407Sets an attribute of name to a given value. 408<p> 409The attribute will be created if it does not exist, or changed if it does. </td> 410 </tr> 411</table> 412<hr>The documentation for this class was generated from the following file:<ul> 413<li><a class="el" href="tinyxml_8h-source.html">tinyxml.h</a></ul> 414<hr size="1"><address style="align: right;"><small>Generated on Sat Oct 8 14:15:30 2005 for TinyXml by 415<a href="http://www.doxygen.org/index.html"> 416<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </small></address> 417</body> 418</html> 419