ReactOS 0.4.15-dev-8096-ga0eec98
tinyxml2::XMLElement Class Reference

#include <tinyxml2.h>

Inheritance diagram for tinyxml2::XMLElement:
Collaboration diagram for tinyxml2::XMLElement:

Public Types

enum  { OPEN , CLOSED , CLOSING }
 

Public Member Functions

const charName () const
 Get the name of an element (which is the Value() of the node.)
 
void SetName (const char *str, bool staticMem=false)
 Set the name of the element.
 
virtual XMLElementToElement ()
 Safely cast to an Element, or null.
 
virtual const XMLElementToElement () const
 
virtual bool Accept (XMLVisitor *visitor) const
 
const charAttribute (const char *name, const char *value=0) const
 
int IntAttribute (const char *name) const
 
unsigned UnsignedAttribute (const char *name) const
 See IntAttribute()
 
bool BoolAttribute (const char *name) const
 See IntAttribute()
 
double DoubleAttribute (const char *name) const
 See IntAttribute()
 
float FloatAttribute (const char *name) const
 See IntAttribute()
 
XMLError QueryIntAttribute (const char *name, int *value) const
 
XMLError QueryUnsignedAttribute (const char *name, unsigned int *value) const
 See QueryIntAttribute()
 
XMLError QueryBoolAttribute (const char *name, bool *value) const
 See QueryIntAttribute()
 
XMLError QueryDoubleAttribute (const char *name, double *value) const
 See QueryIntAttribute()
 
XMLError QueryFloatAttribute (const char *name, float *value) const
 See QueryIntAttribute()
 
int QueryAttribute (const char *name, int *value) const
 
int QueryAttribute (const char *name, unsigned int *value) const
 
int QueryAttribute (const char *name, bool *value) const
 
int QueryAttribute (const char *name, double *value) const
 
int QueryAttribute (const char *name, float *value) const
 
void SetAttribute (const char *name, const char *value)
 Sets the named attribute to value.
 
void SetAttribute (const char *name, int value)
 Sets the named attribute to value.
 
void SetAttribute (const char *name, unsigned value)
 Sets the named attribute to value.
 
void SetAttribute (const char *name, bool value)
 Sets the named attribute to value.
 
void SetAttribute (const char *name, double value)
 Sets the named attribute to value.
 
void SetAttribute (const char *name, float value)
 Sets the named attribute to value.
 
void DeleteAttribute (const char *name)
 
const XMLAttributeFirstAttribute () const
 Return the first attribute in the list.
 
const XMLAttributeFindAttribute (const char *name) const
 Query a specific attribute in the list.
 
const charGetText () const
 
void SetText (const char *inText)
 
void SetText (int value)
 Convenience method for setting text inside an element. See SetText() for important limitations.
 
void SetText (unsigned value)
 Convenience method for setting text inside an element. See SetText() for important limitations.
 
void SetText (bool value)
 Convenience method for setting text inside an element. See SetText() for important limitations.
 
void SetText (double value)
 Convenience method for setting text inside an element. See SetText() for important limitations.
 
void SetText (float value)
 Convenience method for setting text inside an element. See SetText() for important limitations.
 
XMLError QueryIntText (int *ival) const
 
XMLError QueryUnsignedText (unsigned *uval) const
 See QueryIntText()
 
XMLError QueryBoolText (bool *bval) const
 See QueryIntText()
 
XMLError QueryDoubleText (double *dval) const
 See QueryIntText()
 
XMLError QueryFloatText (float *fval) const
 See QueryIntText()
 
int ClosingType () const
 
virtual XMLNodeShallowClone (XMLDocument *document) const
 
virtual bool ShallowEqual (const XMLNode *compare) const
 
- Public Member Functions inherited from tinyxml2::XMLNode
const XMLDocumentGetDocument () const
 Get the XMLDocument that owns this XMLNode.
 
XMLDocumentGetDocument ()
 Get the XMLDocument that owns this XMLNode.
 
virtual XMLElementToElement ()
 Safely cast to an Element, or null.
 
virtual XMLTextToText ()
 Safely cast to Text, or null.
 
virtual XMLCommentToComment ()
 Safely cast to a Comment, or null.
 
virtual XMLDocumentToDocument ()
 Safely cast to a Document, or null.
 
virtual XMLDeclarationToDeclaration ()
 Safely cast to a Declaration, or null.
 
virtual XMLUnknownToUnknown ()
 Safely cast to an Unknown, or null.
 
virtual const XMLElementToElement () const
 
virtual const XMLTextToText () const
 
virtual const XMLCommentToComment () const
 
virtual const XMLDocumentToDocument () const
 
virtual const XMLDeclarationToDeclaration () const
 
virtual const XMLUnknownToUnknown () const
 
const charValue () const
 
void SetValue (const char *val, bool staticMem=false)
 
const XMLNodeParent () const
 Get the parent of this node on the DOM.
 
XMLNodeParent ()
 
bool NoChildren () const
 Returns true if this node has no children.
 
const XMLNodeFirstChild () const
 Get the first child node, or null if none exists.
 
XMLNodeFirstChild ()
 
const XMLElementFirstChildElement (const char *name=0) const
 
XMLElementFirstChildElement (const char *name=0)
 
const XMLNodeLastChild () const
 Get the last child node, or null if none exists.
 
XMLNodeLastChild ()
 
const XMLElementLastChildElement (const char *name=0) const
 
XMLElementLastChildElement (const char *name=0)
 
const XMLNodePreviousSibling () const
 Get the previous (left) sibling node of this node.
 
XMLNodePreviousSibling ()
 
const XMLElementPreviousSiblingElement (const char *name=0) const
 Get the previous (left) sibling element of this node, with an optionally supplied name.
 
XMLElementPreviousSiblingElement (const char *name=0)
 
const XMLNodeNextSibling () const
 Get the next (right) sibling node of this node.
 
XMLNodeNextSibling ()
 
const XMLElementNextSiblingElement (const char *name=0) const
 Get the next (right) sibling element of this node, with an optionally supplied name.
 
XMLElementNextSiblingElement (const char *name=0)
 
XMLNodeInsertEndChild (XMLNode *addThis)
 
XMLNodeLinkEndChild (XMLNode *addThis)
 
XMLNodeInsertFirstChild (XMLNode *addThis)
 
XMLNodeInsertAfterChild (XMLNode *afterThis, XMLNode *addThis)
 
void DeleteChildren ()
 
void DeleteChild (XMLNode *node)
 
virtual XMLNodeShallowClone (XMLDocument *document) const =0
 
virtual bool ShallowEqual (const XMLNode *compare) const =0
 
virtual bool Accept (XMLVisitor *visitor) const =0
 

Protected Member Functions

charParseDeep (char *p, StrPair *endTag)
 
- Protected Member Functions inherited from tinyxml2::XMLNode
 XMLNode (XMLDocument *)
 
virtual ~XMLNode ()
 
virtual charParseDeep (char *, StrPair *)
 

Private Types

enum  { BUF_SIZE = 200 }
 

Private Member Functions

 XMLElement (XMLDocument *doc)
 
virtual ~XMLElement ()
 
 XMLElement (const XMLElement &)
 
void operator= (const XMLElement &)
 
XMLAttributeFindAttribute (const char *name)
 
XMLAttributeFindOrCreateAttribute (const char *name)
 
charParseAttributes (char *p)
 

Static Private Member Functions

static void DeleteAttribute (XMLAttribute *attribute)
 

Private Attributes

int _closingType
 
XMLAttribute_rootAttribute
 

Friends

class XMLBase
 
class XMLDocument
 

Additional Inherited Members

- Protected Attributes inherited from tinyxml2::XMLNode
XMLDocument_document
 
XMLNode_parent
 
StrPair _value
 
XMLNode_firstChild
 
XMLNode_lastChild
 
XMLNode_prev
 
XMLNode_next
 

Detailed Description

The element is a container class. It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes.

Definition at line 1143 of file tinyxml2.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
OPEN 
CLOSED 
CLOSING 

Definition at line 1472 of file tinyxml2.h.

1472 {
1473 OPEN, // <foo>
1474 CLOSED, // <foo/>
1475 CLOSING // </foo>
1476 };

◆ anonymous enum

anonymous enum
private
Enumerator
BUF_SIZE 

Definition at line 1500 of file tinyxml2.h.

1500{ BUF_SIZE = 200 };

Constructor & Destructor Documentation

◆ XMLElement() [1/2]

tinyxml2::XMLElement::XMLElement ( XMLDocument doc)
private

Definition at line 1376 of file tinyxml2.cpp.

1376 : XMLNode( doc ),
1377 _closingType( 0 ),
1378 _rootAttribute( 0 )
1379{
1380}
XMLAttribute * _rootAttribute
Definition: tinyxml2.h:1505
XMLNode(XMLDocument *)
Definition: tinyxml2.cpp:701

◆ ~XMLElement()

tinyxml2::XMLElement::~XMLElement ( )
privatevirtual

Definition at line 1383 of file tinyxml2.cpp.

1384{
1385 while( _rootAttribute ) {
1386 XMLAttribute* next = _rootAttribute->_next;
1389 }
1390}
XMLAttribute * _next
Definition: tinyxml2.h:1134
void DeleteAttribute(const char *name)
Definition: tinyxml2.cpp:1571
static unsigned __int64 next
Definition: rand_nt.c:6

◆ XMLElement() [2/2]

tinyxml2::XMLElement::XMLElement ( const XMLElement )
private

Member Function Documentation

◆ Accept()

bool tinyxml2::XMLElement::Accept ( XMLVisitor visitor) const
virtual

Accept a hierarchical visit of the nodes in the TinyXML-2 DOM. Every node in the XML tree will be conditionally visited and the host will be called back via the XMLVisitor interface.

This is essentially a SAX interface for TinyXML-2. (Note however it doesn't re-parse the XML for the callbacks, so the performance of TinyXML-2 is unchanged by using this interface versus any other.)

The interface has been based on ideas from:

Which are both good references for "visiting".

An example of using Accept():

XMLPrinter printer;
tinyxmlDoc.Accept( &printer );
const char* xmlcstr = printer.CStr();

Implements tinyxml2::XMLNode.

Definition at line 1729 of file tinyxml2.cpp.

1730{
1731 TIXMLASSERT( visitor );
1732 if ( visitor->VisitEnter( *this, _rootAttribute ) ) {
1733 for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) {
1734 if ( !node->Accept( visitor ) ) {
1735 break;
1736 }
1737 }
1738 }
1739 return visitor->VisitExit( *this );
1740}
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:705
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
Definition: dlist.c:348

◆ Attribute()

const char * tinyxml2::XMLElement::Attribute ( const char name,
const char value = 0 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. For example:

const char* value = ele->Attribute( "foo" );

The 'value' parameter is normally null. However, if specified, the attribute will only be returned if the 'name' and 'value' match. This allow you to write code:

if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar();

rather than:

if ( ele->Attribute( "foo" ) ) {
    if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar();
}

Definition at line 1404 of file tinyxml2.cpp.

1405{
1406 const XMLAttribute* a = FindAttribute( name );
1407 if ( !a ) {
1408 return 0;
1409 }
1410 if ( !value || XMLUtil::StringEqual( a->Value(), value )) {
1411 return a->Value();
1412 }
1413 return 0;
1414}
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
Definition: tinyxml2.cpp:1393
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition: tinyxml2.h:555
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
Definition: name.c:39
Definition: pdh_main.c:94

Referenced by ParseAttributes().

◆ BoolAttribute()

bool tinyxml2::XMLElement::BoolAttribute ( const char name) const
inline

See IntAttribute()

Definition at line 1207 of file tinyxml2.h.

1207 {
1208 bool b=false;
1210 return b;
1211 }
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1254
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define b
Definition: ke_i.h:79

◆ ClosingType()

int tinyxml2::XMLElement::ClosingType ( ) const
inline

Definition at line 1477 of file tinyxml2.h.

1477 {
1478 return _closingType;
1479 }

Referenced by tinyxml2::XMLNode::ParseDeep().

◆ DeleteAttribute() [1/2]

void tinyxml2::XMLElement::DeleteAttribute ( const char name)

Delete an attribute.

Definition at line 1571 of file tinyxml2.cpp.

1572{
1573 XMLAttribute* prev = 0;
1574 for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) {
1575 if ( XMLUtil::StringEqual( name, a->Name() ) ) {
1576 if ( prev ) {
1577 prev->_next = a->_next;
1578 }
1579 else {
1581 }
1582 DeleteAttribute( a );
1583 break;
1584 }
1585 prev = a;
1586 }
1587}
#define a
Definition: ke_i.h:78

Referenced by DeleteAttribute(), ParseAttributes(), and ~XMLElement().

◆ DeleteAttribute() [2/2]

void tinyxml2::XMLElement::DeleteAttribute ( XMLAttribute attribute)
staticprivate

Definition at line 1647 of file tinyxml2.cpp.

1648{
1649 if ( attribute == 0 ) {
1650 return;
1651 }
1652 MemPool* pool = attribute->_memPool;
1653 attribute->~XMLAttribute();
1654 pool->Free( attribute );
1655}

◆ DoubleAttribute()

double tinyxml2::XMLElement::DoubleAttribute ( const char name) const
inline

See IntAttribute()

Definition at line 1213 of file tinyxml2.h.

1213 {
1214 double d=0;
1216 return d;
1217 }
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1262
#define d
Definition: ke_i.h:81

◆ FindAttribute() [1/2]

XMLAttribute * tinyxml2::XMLElement::FindAttribute ( const char name)
inlineprivate

Definition at line 1492 of file tinyxml2.h.

1492 {
1493 return const_cast<XMLAttribute*>(const_cast<const XMLElement*>(this)->FindAttribute( name ));
1494 }
friend class XMLElement
Definition: tinyxml2.h:616

◆ FindAttribute() [2/2]

const XMLAttribute * tinyxml2::XMLElement::FindAttribute ( const char name) const

Query a specific attribute in the list.

Definition at line 1393 of file tinyxml2.cpp.

1394{
1395 for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) {
1396 if ( XMLUtil::StringEqual( a->Name(), name ) ) {
1397 return a;
1398 }
1399 }
1400 return 0;
1401}

Referenced by Attribute().

◆ FindOrCreateAttribute()

XMLAttribute * tinyxml2::XMLElement::FindOrCreateAttribute ( const char name)
private

Definition at line 1543 of file tinyxml2.cpp.

1544{
1545 XMLAttribute* last = 0;
1546 XMLAttribute* attrib = 0;
1547 for( attrib = _rootAttribute;
1548 attrib;
1549 last = attrib, attrib = attrib->_next ) {
1550 if ( XMLUtil::StringEqual( attrib->Name(), name ) ) {
1551 break;
1552 }
1553 }
1554 if ( !attrib ) {
1555 TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
1556 attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
1557 attrib->_memPool = &_document->_attributePool;
1558 if ( last ) {
1559 last->_next = attrib;
1560 }
1561 else {
1562 _rootAttribute = attrib;
1563 }
1564 attrib->SetName( name );
1565 attrib->_memPool->SetTracked(); // always created and linked.
1566 }
1567 return attrib;
1568}
void SetName(const char *name)
Definition: tinyxml2.cpp:1280
MemPoolT< sizeof(XMLAttribute) > _attributePool
Definition: tinyxml2.h:1723
XMLDocument * _document
Definition: tinyxml2.h:861
static UINT UINT last
Definition: font.c:45

◆ FirstAttribute()

const XMLAttribute * tinyxml2::XMLElement::FirstAttribute ( ) const
inline

Return the first attribute in the list.

Definition at line 1353 of file tinyxml2.h.

1353 {
1354 return _rootAttribute;
1355 }

Referenced by ShallowClone(), and ShallowEqual().

◆ FloatAttribute()

float tinyxml2::XMLElement::FloatAttribute ( const char name) const
inline

See IntAttribute()

Definition at line 1219 of file tinyxml2.h.

1219 {
1220 float f=0;
1222 return f;
1223 }
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1270
GLfloat f
Definition: glext.h:7540
#define f
Definition: ke_i.h:83

◆ GetText()

const char * tinyxml2::XMLElement::GetText ( ) const

Convenience function for easy access to the text inside an element. Although easy and concise, GetText() is limited compared to getting the XMLText child and accessing it directly.

If the first child of 'this' is a XMLText, the GetText() returns the character string of the Text node, else null is returned.

This is a convenient method for getting the text of simple contained text:

<foo>This is text</foo>
    const char* str = fooElement->GetText();

'str' will be a pointer to "This is text".

Note that this function can be misleading. If the element foo was created from this XML:

    <foo><b>This is text</b></foo>

then the value of str would be null. The first child node isn't a text node, it is another element. From this XML:

    <foo>This is <b>text</b></foo>

GetText() will return "This is ".

Definition at line 1417 of file tinyxml2.cpp.

1418{
1419 if ( FirstChild() && FirstChild()->ToText() ) {
1420 return FirstChild()->Value();
1421 }
1422 return 0;
1423}
const char * Value() const
Definition: tinyxml2.cpp:719
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:635

◆ IntAttribute()

int tinyxml2::XMLElement::IntAttribute ( const char name) const
inline

Given an attribute name, IntAttribute() returns the value of the attribute interpreted as an integer. 0 will be returned if there is an error. For a method with error checking, see QueryIntAttribute()

Definition at line 1195 of file tinyxml2.h.

1195 {
1196 int i=0;
1198 return i;
1199 }
XMLError QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1238
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

◆ Name()

const char * tinyxml2::XMLElement::Name ( ) const
inline

Get the name of an element (which is the Value() of the node.)

Definition at line 1149 of file tinyxml2.h.

1149 {
1150 return Value();
1151 }
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by ParseAttributes(), and tinyxml2::XMLNode::ParseDeep().

◆ operator=()

void tinyxml2::XMLElement::operator= ( const XMLElement )
private

◆ ParseAttributes()

char * tinyxml2::XMLElement::ParseAttributes ( char p)
private

Definition at line 1590 of file tinyxml2.cpp.

1591{
1592 const char* start = p;
1593 XMLAttribute* prevAttribute = 0;
1594
1595 // Read the attributes.
1596 while( p ) {
1598 if ( !(*p) ) {
1600 return 0;
1601 }
1602
1603 // attribute.
1604 if (XMLUtil::IsNameStartChar( *p ) ) {
1605 TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
1606 XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
1607 attrib->_memPool = &_document->_attributePool;
1608 attrib->_memPool->SetTracked();
1609
1610 p = attrib->ParseDeep( p, _document->ProcessEntities() );
1611 if ( !p || Attribute( attrib->Name() ) ) {
1612 DeleteAttribute( attrib );
1614 return 0;
1615 }
1616 // There is a minor bug here: if the attribute in the source xml
1617 // document is duplicated, it will not be detected and the
1618 // attribute will be doubly added. However, tracking the 'prevAttribute'
1619 // avoids re-scanning the attribute list. Preferring performance for
1620 // now, may reconsider in the future.
1621 if ( prevAttribute ) {
1622 prevAttribute->_next = attrib;
1623 }
1624 else {
1625 _rootAttribute = attrib;
1626 }
1627 prevAttribute = attrib;
1628 }
1629 // end of the tag
1630 else if ( *p == '>' ) {
1631 ++p;
1632 break;
1633 }
1634 // end of the tag
1635 else if ( *p == '/' && *(p+1) == '>' ) {
1637 return p+2; // done; sealed element.
1638 }
1639 else {
1641 return 0;
1642 }
1643 }
1644 return p;
1645}
bool ProcessEntities() const
Definition: tinyxml2.h:1585
void SetError(XMLError error, const char *str1, const char *str2)
Definition: tinyxml2.cpp:2053
const char * Attribute(const char *name, const char *value=0) const
Definition: tinyxml2.cpp:1404
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition: tinyxml2.h:1149
static const char * SkipWhiteSpace(const char *p)
Definition: tinyxml2.h:519
static bool IsNameStartChar(unsigned char ch)
Definition: tinyxml2.h:537
GLuint start
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902
@ XML_ERROR_PARSING_ATTRIBUTE
Definition: tinyxml2.h:496
@ XML_ERROR_PARSING_ELEMENT
Definition: tinyxml2.h:495

Referenced by ParseDeep().

◆ ParseDeep()

char * tinyxml2::XMLElement::ParseDeep ( char p,
StrPair endTag 
)
protectedvirtual

Reimplemented from tinyxml2::XMLNode.

Definition at line 1661 of file tinyxml2.cpp.

1662{
1663 // Read the element name.
1665
1666 // The closing element is the </element> form. It is
1667 // parsed just like a regular element then deleted from
1668 // the DOM.
1669 if ( *p == '/' ) {
1671 ++p;
1672 }
1673
1674 p = _value.ParseName( p );
1675 if ( _value.Empty() ) {
1676 return 0;
1677 }
1678
1679 p = ParseAttributes( p );
1680 if ( !p || !*p || _closingType ) {
1681 return p;
1682 }
1683
1684 p = XMLNode::ParseDeep( p, strPair );
1685 return p;
1686}
char * ParseName(char *in)
Definition: tinyxml2.cpp:211
bool Empty() const
Definition: tinyxml2.h:144
char * ParseAttributes(char *p)
Definition: tinyxml2.cpp:1590
StrPair _value
Definition: tinyxml2.h:863
virtual char * ParseDeep(char *, StrPair *)
Definition: tinyxml2.cpp:930

◆ QueryAttribute() [1/5]

int tinyxml2::XMLElement::QueryAttribute ( const char name,
bool value 
) const
inline

Definition at line 1304 of file tinyxml2.h.

1304 {
1305 return QueryBoolAttribute( name, value );
1306 }

◆ QueryAttribute() [2/5]

int tinyxml2::XMLElement::QueryAttribute ( const char name,
double value 
) const
inline

Definition at line 1308 of file tinyxml2.h.

1308 {
1309 return QueryDoubleAttribute( name, value );
1310 }

◆ QueryAttribute() [3/5]

int tinyxml2::XMLElement::QueryAttribute ( const char name,
float value 
) const
inline

Definition at line 1312 of file tinyxml2.h.

1312 {
1313 return QueryFloatAttribute( name, value );
1314 }

◆ QueryAttribute() [4/5]

int tinyxml2::XMLElement::QueryAttribute ( const char name,
int value 
) const
inline

Given an attribute name, QueryAttribute() returns XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. It is overloaded for the primitive types, and is a generally more convenient replacement of QueryIntAttribute() and related functions.

If successful, the result of the conversion will be written to 'value'. If not successful, nothing will be written to 'value'. This allows you to provide default value:

int value = 10;
QueryAttribute( "foo", &value );        // if "foo" isn't found, value will still be 10

Definition at line 1296 of file tinyxml2.h.

1296 {
1297 return QueryIntAttribute( name, value );
1298 }

◆ QueryAttribute() [5/5]

int tinyxml2::XMLElement::QueryAttribute ( const char name,
unsigned int value 
) const
inline

Definition at line 1300 of file tinyxml2.h.

1300 {
1302 }
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1246

◆ QueryBoolAttribute()

XMLError tinyxml2::XMLElement::QueryBoolAttribute ( const char name,
bool value 
) const
inline

See QueryIntAttribute()

Definition at line 1254 of file tinyxml2.h.

1254 {
1255 const XMLAttribute* a = FindAttribute( name );
1256 if ( !a ) {
1257 return XML_NO_ATTRIBUTE;
1258 }
1259 return a->QueryBoolValue( value );
1260 }
@ XML_NO_ATTRIBUTE
Definition: tinyxml2.h:489

◆ QueryBoolText()

XMLError tinyxml2::XMLElement::QueryBoolText ( bool bval) const

See QueryIntText()

Definition at line 1503 of file tinyxml2.cpp.

1504{
1505 if ( FirstChild() && FirstChild()->ToText() ) {
1506 const char* t = FirstChild()->Value();
1507 if ( XMLUtil::ToBool( t, bval ) ) {
1508 return XML_SUCCESS;
1509 }
1511 }
1512 return XML_NO_TEXT_NODE;
1513}
static bool ToBool(const char *str, bool *value)
Definition: tinyxml2.cpp:575
float bval
Definition: cylfrac.c:48
GLdouble GLdouble t
Definition: gl.h:2047
@ XML_SUCCESS
Definition: tinyxml2.h:487
@ XML_NO_TEXT_NODE
Definition: tinyxml2.h:507
@ XML_CAN_NOT_CONVERT_TEXT
Definition: tinyxml2.h:506

◆ QueryDoubleAttribute()

XMLError tinyxml2::XMLElement::QueryDoubleAttribute ( const char name,
double value 
) const
inline

See QueryIntAttribute()

Definition at line 1262 of file tinyxml2.h.

1262 {
1263 const XMLAttribute* a = FindAttribute( name );
1264 if ( !a ) {
1265 return XML_NO_ATTRIBUTE;
1266 }
1267 return a->QueryDoubleValue( value );
1268 }

◆ QueryDoubleText()

XMLError tinyxml2::XMLElement::QueryDoubleText ( double dval) const

See QueryIntText()

Definition at line 1516 of file tinyxml2.cpp.

1517{
1518 if ( FirstChild() && FirstChild()->ToText() ) {
1519 const char* t = FirstChild()->Value();
1520 if ( XMLUtil::ToDouble( t, dval ) ) {
1521 return XML_SUCCESS;
1522 }
1524 }
1525 return XML_NO_TEXT_NODE;
1526}
static bool ToDouble(const char *str, double *value)
Definition: tinyxml2.cpp:602
double dval
Definition: format.c:274

◆ QueryFloatAttribute()

XMLError tinyxml2::XMLElement::QueryFloatAttribute ( const char name,
float value 
) const
inline

See QueryIntAttribute()

Definition at line 1270 of file tinyxml2.h.

1270 {
1271 const XMLAttribute* a = FindAttribute( name );
1272 if ( !a ) {
1273 return XML_NO_ATTRIBUTE;
1274 }
1275 return a->QueryFloatValue( value );
1276 }

◆ QueryFloatText()

XMLError tinyxml2::XMLElement::QueryFloatText ( float fval) const

See QueryIntText()

Definition at line 1529 of file tinyxml2.cpp.

1530{
1531 if ( FirstChild() && FirstChild()->ToText() ) {
1532 const char* t = FirstChild()->Value();
1533 if ( XMLUtil::ToFloat( t, fval ) ) {
1534 return XML_SUCCESS;
1535 }
1537 }
1538 return XML_NO_TEXT_NODE;
1539}
static bool ToFloat(const char *str, float *value)
Definition: tinyxml2.cpp:594

◆ QueryIntAttribute()

XMLError tinyxml2::XMLElement::QueryIntAttribute ( const char name,
int value 
) const
inline

Given an attribute name, QueryIntAttribute() returns XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. If successful, the result of the conversion will be written to 'value'. If not successful, nothing will be written to 'value'. This allows you to provide default value:

int value = 10;
QueryIntAttribute( "foo", &value );     // if "foo" isn't found, value will still be 10

Definition at line 1238 of file tinyxml2.h.

1238 {
1239 const XMLAttribute* a = FindAttribute( name );
1240 if ( !a ) {
1241 return XML_NO_ATTRIBUTE;
1242 }
1243 return a->QueryIntValue( value );
1244 }

◆ QueryIntText()

XMLError tinyxml2::XMLElement::QueryIntText ( int ival) const

Convenience method to query the value of a child text node. This is probably best shown by example. Given you have a document is this form:

    <point>
        <x>1</x>
        <y>1.4</y>
    </point>

The QueryIntText() and similar functions provide a safe and easier way to get to the "value" of x and y.

    int x = 0;
    float y = 0;    // types of x and y are contrived for example
    const XMLElement* xElement = pointElement->FirstChildElement( "x" );
    const XMLElement* yElement = pointElement->FirstChildElement( "y" );
    xElement->QueryIntText( &x );
    yElement->QueryFloatText( &y );
Returns
XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted to the requested type, and XML_NO_TEXT_NODE if there is no child text to query.

Definition at line 1477 of file tinyxml2.cpp.

1478{
1479 if ( FirstChild() && FirstChild()->ToText() ) {
1480 const char* t = FirstChild()->Value();
1481 if ( XMLUtil::ToInt( t, ival ) ) {
1482 return XML_SUCCESS;
1483 }
1485 }
1486 return XML_NO_TEXT_NODE;
1487}
static bool ToInt(const char *str, int *value)
Definition: tinyxml2.cpp:559

◆ QueryUnsignedAttribute()

XMLError tinyxml2::XMLElement::QueryUnsignedAttribute ( const char name,
unsigned int value 
) const
inline

See QueryIntAttribute()

Definition at line 1246 of file tinyxml2.h.

1246 {
1247 const XMLAttribute* a = FindAttribute( name );
1248 if ( !a ) {
1249 return XML_NO_ATTRIBUTE;
1250 }
1251 return a->QueryUnsignedValue( value );
1252 }

◆ QueryUnsignedText()

XMLError tinyxml2::XMLElement::QueryUnsignedText ( unsigned uval) const

See QueryIntText()

Definition at line 1490 of file tinyxml2.cpp.

1491{
1492 if ( FirstChild() && FirstChild()->ToText() ) {
1493 const char* t = FirstChild()->Value();
1494 if ( XMLUtil::ToUnsigned( t, uval ) ) {
1495 return XML_SUCCESS;
1496 }
1498 }
1499 return XML_NO_TEXT_NODE;
1500}
static bool ToUnsigned(const char *str, unsigned *value)
Definition: tinyxml2.cpp:567

◆ SetAttribute() [1/6]

void tinyxml2::XMLElement::SetAttribute ( const char name,
bool  value 
)
inline

Sets the named attribute to value.

Definition at line 1332 of file tinyxml2.h.

1332 {
1333 XMLAttribute* a = FindOrCreateAttribute( name );
1334 a->SetAttribute( value );
1335 }
XMLAttribute * FindOrCreateAttribute(const char *name)
Definition: tinyxml2.cpp:1543

◆ SetAttribute() [2/6]

void tinyxml2::XMLElement::SetAttribute ( const char name,
const char value 
)
inline

Sets the named attribute to value.

Definition at line 1317 of file tinyxml2.h.

1317 {
1318 XMLAttribute* a = FindOrCreateAttribute( name );
1319 a->SetAttribute( value );
1320 }

◆ SetAttribute() [3/6]

void tinyxml2::XMLElement::SetAttribute ( const char name,
double  value 
)
inline

Sets the named attribute to value.

Definition at line 1337 of file tinyxml2.h.

1337 {
1338 XMLAttribute* a = FindOrCreateAttribute( name );
1339 a->SetAttribute( value );
1340 }

◆ SetAttribute() [4/6]

void tinyxml2::XMLElement::SetAttribute ( const char name,
float  value 
)
inline

Sets the named attribute to value.

Definition at line 1342 of file tinyxml2.h.

1342 {
1343 XMLAttribute* a = FindOrCreateAttribute( name );
1344 a->SetAttribute( value );
1345 }

◆ SetAttribute() [5/6]

void tinyxml2::XMLElement::SetAttribute ( const char name,
int  value 
)
inline

Sets the named attribute to value.

Definition at line 1322 of file tinyxml2.h.

1322 {
1323 XMLAttribute* a = FindOrCreateAttribute( name );
1324 a->SetAttribute( value );
1325 }

◆ SetAttribute() [6/6]

void tinyxml2::XMLElement::SetAttribute ( const char name,
unsigned  value 
)
inline

Sets the named attribute to value.

Definition at line 1327 of file tinyxml2.h.

1327 {
1328 XMLAttribute* a = FindOrCreateAttribute( name );
1329 a->SetAttribute( value );
1330 }

◆ SetName()

void tinyxml2::XMLElement::SetName ( const char str,
bool  staticMem = false 
)
inline

Set the name of the element.

Definition at line 1153 of file tinyxml2.h.

1153 {
1154 SetValue( str, staticMem );
1155 }
@ SetValue
Definition: shader.c:1968
const WCHAR * str

Referenced by tinyxml2::XMLDocument::NewElement().

◆ SetText() [1/6]

void tinyxml2::XMLElement::SetText ( bool  value)

Convenience method for setting text inside an element. See SetText() for important limitations.

Definition at line 1453 of file tinyxml2.cpp.

1454{
1455 char buf[BUF_SIZE];
1457 SetText( buf );
1458}
void SetText(const char *inText)
Definition: tinyxml2.cpp:1426
static void ToStr(int v, char *buffer, int bufferSize)
Definition: tinyxml2.cpp:526
const GLdouble * v
Definition: gl.h:2040
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751

◆ SetText() [2/6]

void tinyxml2::XMLElement::SetText ( const char inText)

Convenience function for easy access to the text inside an element. Although easy and concise, SetText() is limited compared to creating an XMLText child and mutating it directly.

If the first child of 'this' is a XMLText, SetText() sets its value to the given string, otherwise it will create a first child that is an XMLText.

This is a convenient method for setting the text of simple contained text:

<foo>This is text</foo>
    fooElement->SetText( "Hullaballoo!" );
<foo>Hullaballoo!</foo>

Note that this function can be misleading. If the element foo was created from this XML:

    <foo><b>This is text</b></foo>

then it will not change "This is text", but rather prefix it with a text element:

    <foo>Hullaballoo!<b>This is text</b></foo>

For this XML:

    <foo />

SetText() will generate

    <foo>Hullaballoo!</foo>

Definition at line 1426 of file tinyxml2.cpp.

1427{
1428 if ( FirstChild() && FirstChild()->ToText() )
1429 FirstChild()->SetValue( inText );
1430 else {
1431 XMLText* theText = GetDocument()->NewText( inText );
1432 InsertFirstChild( theText );
1433 }
1434}
XMLText * NewText(const char *text)
Definition: tinyxml2.cpp:1843
void SetValue(const char *val, bool staticMem=false)
Definition: tinyxml2.cpp:727
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:620
XMLNode * InsertFirstChild(XMLNode *addThis)
Definition: tinyxml2.cpp:814

Referenced by SetText().

◆ SetText() [3/6]

void tinyxml2::XMLElement::SetText ( double  value)

Convenience method for setting text inside an element. See SetText() for important limitations.

Definition at line 1469 of file tinyxml2.cpp.

1470{
1471 char buf[BUF_SIZE];
1473 SetText( buf );
1474}

◆ SetText() [4/6]

void tinyxml2::XMLElement::SetText ( float  value)

Convenience method for setting text inside an element. See SetText() for important limitations.

Definition at line 1461 of file tinyxml2.cpp.

1462{
1463 char buf[BUF_SIZE];
1465 SetText( buf );
1466}

◆ SetText() [5/6]

void tinyxml2::XMLElement::SetText ( int  value)

Convenience method for setting text inside an element. See SetText() for important limitations.

Definition at line 1437 of file tinyxml2.cpp.

1438{
1439 char buf[BUF_SIZE];
1441 SetText( buf );
1442}

◆ SetText() [6/6]

void tinyxml2::XMLElement::SetText ( unsigned  value)

Convenience method for setting text inside an element. See SetText() for important limitations.

Definition at line 1445 of file tinyxml2.cpp.

1446{
1447 char buf[BUF_SIZE];
1449 SetText( buf );
1450}

◆ ShallowClone()

XMLNode * tinyxml2::XMLElement::ShallowClone ( XMLDocument document) const
virtual

Make a copy of this node, but not its children. You may pass in a Document pointer that will be the owner of the new Node. If the 'document' is null, then the node returned will be allocated from the current Document. (this->GetDocument())

Note: if called on a XMLDocument, this will return null.

Implements tinyxml2::XMLNode.

Definition at line 1690 of file tinyxml2.cpp.

1691{
1692 if ( !doc ) {
1693 doc = _document;
1694 }
1695 XMLElement* element = doc->NewElement( Value() ); // fixme: this will always allocate memory. Intern?
1696 for( const XMLAttribute* a=FirstAttribute(); a; a=a->Next() ) {
1697 element->SetAttribute( a->Name(), a->Value() ); // fixme: this will always allocate memory. Intern?
1698 }
1699 return element;
1700}
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition: tinyxml2.h:1353

◆ ShallowEqual()

bool tinyxml2::XMLElement::ShallowEqual ( const XMLNode compare) const
virtual

Test if 2 nodes are the same, but don't test children. The 2 nodes do not need to be in the same Document.

Note: if called on a XMLDocument, this will return false.

Implements tinyxml2::XMLNode.

Definition at line 1703 of file tinyxml2.cpp.

1704{
1706 const XMLElement* other = compare->ToElement();
1707 if ( other && XMLUtil::StringEqual( other->Name(), Name() )) {
1708
1709 const XMLAttribute* a=FirstAttribute();
1710 const XMLAttribute* b=other->FirstAttribute();
1711
1712 while ( a && b ) {
1713 if ( !XMLUtil::StringEqual( a->Value(), b->Value() ) ) {
1714 return false;
1715 }
1716 a = a->Next();
1717 b = b->Next();
1718 }
1719 if ( a || b ) {
1720 // different count
1721 return false;
1722 }
1723 return true;
1724 }
1725 return false;
1726}
int other
Definition: msacm.c:1376
Definition: bug.cpp:8

◆ ToElement() [1/2]

virtual XMLElement * tinyxml2::XMLElement::ToElement ( )
inlinevirtual

Safely cast to an Element, or null.

Reimplemented from tinyxml2::XMLNode.

Definition at line 1157 of file tinyxml2.h.

1157 {
1158 return this;
1159 }

◆ ToElement() [2/2]

virtual const XMLElement * tinyxml2::XMLElement::ToElement ( ) const
inlinevirtual

Reimplemented from tinyxml2::XMLNode.

Definition at line 1160 of file tinyxml2.h.

1160 {
1161 return this;
1162 }

◆ UnsignedAttribute()

unsigned tinyxml2::XMLElement::UnsignedAttribute ( const char name) const
inline

See IntAttribute()

Definition at line 1201 of file tinyxml2.h.

1201 {
1202 unsigned i=0;
1204 return i;
1205 }

Friends And Related Function Documentation

◆ XMLBase

friend class XMLBase
friend

Definition at line 1145 of file tinyxml2.h.

◆ XMLDocument

friend class XMLDocument
friend

Definition at line 1146 of file tinyxml2.h.

Member Data Documentation

◆ _closingType

int tinyxml2::XMLElement::_closingType
private

Definition at line 1501 of file tinyxml2.h.

Referenced by ParseAttributes(), and ParseDeep().

◆ _rootAttribute

XMLAttribute* tinyxml2::XMLElement::_rootAttribute
private

The documentation for this class was generated from the following files: