osgEarth 2.1.1
Public Member Functions | Protected Member Functions | Private Attributes

TiXmlElement Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlElement:
Collaboration diagram for TiXmlElement:

List of all members.

Public Member Functions

 TiXmlElement (const char *in_value)
 Construct an element.
 TiXmlElement (const TiXmlElement &)
void operator= (const TiXmlElement &base)
virtual ~TiXmlElement ()
const char * Attribute (const char *name) const
const char * Attribute (const char *name, int *i) const
const char * Attribute (const char *name, double *d) const
int QueryIntAttribute (const char *name, int *_value) const
int QueryDoubleAttribute (const char *name, double *_value) const
 QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
int QueryFloatAttribute (const char *name, float *_value) const
 QueryFloatAttribute examines the attribute - see QueryIntAttribute().
void SetAttribute (const char *name, const char *_value)
void SetAttribute (const char *name, int value)
void SetDoubleAttribute (const char *name, double value)
void RemoveAttribute (const char *name)
const TiXmlAttributeFirstAttribute () const
 Access the first attribute in this element.
TiXmlAttributeFirstAttribute ()
const TiXmlAttributeLastAttribute () const
 Access the last attribute in this element.
TiXmlAttributeLastAttribute ()
const char * GetText () const
virtual TiXmlNodeClone () const
 Creates a new Element and returns it - the returned element is a copy.
virtual void Print (FILE *cfile, int depth) const
virtual const char * Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlElementToElement () const
 Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlElementToElement ()
 Cast to a more defined type. Will return null not of the requested type.
virtual bool Accept (TiXmlVisitor *visitor) const

Protected Member Functions

void CopyTo (TiXmlElement *target) const
void ClearThis ()
const char * ReadValue (const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)

Private Attributes

TiXmlAttributeSet attributeSet

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 940 of file tinyxml.h.


Constructor & Destructor Documentation

TiXmlElement::TiXmlElement ( const char *  in_value)

Construct an element.

Definition at line 521 of file tinyxml.cpp.

Here is the caller graph for this function:

TiXmlElement::TiXmlElement ( const TiXmlElement copy)

Definition at line 539 of file tinyxml.cpp.

Here is the call graph for this function:

TiXmlElement::~TiXmlElement ( ) [virtual]

Definition at line 554 of file tinyxml.cpp.

{
        ClearThis();
}

Here is the call graph for this function:


Member Function Documentation

bool TiXmlElement::Accept ( TiXmlVisitor visitor) const [virtual]

Walk the XML tree visiting this node and all of its children.

Implements TiXmlNode.

Definition at line 831 of file tinyxml.cpp.

{
        if ( visitor->VisitEnter( *this, attributeSet.First() ) ) 
        {
                for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
                {
                        if ( !node->Accept( visitor ) )
                                break;
                }
        }
        return visitor->VisitExit( *this );
}

Here is the call graph for this function:

const char * TiXmlElement::Attribute ( const char *  name) const

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

Definition at line 572 of file tinyxml.cpp.

{
        const TiXmlAttribute* node = attributeSet.Find( name );
        if ( node )
                return node->Value();
        return 0;
}

Here is the call graph for this function:

const char * TiXmlElement::Attribute ( const char *  name,
double *  d 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. If 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.

Definition at line 624 of file tinyxml.cpp.

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        const char* result = 0;

        if ( attrib ) {
                result = attrib->Value();
                if ( d ) {
                        attrib->QueryDoubleValue( d );
                }
        }
        return result;
}

Here is the call graph for this function:

const char * TiXmlElement::Attribute ( const char *  name,
int *  i 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. If 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.

Definition at line 592 of file tinyxml.cpp.

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        const char* result = 0;

        if ( attrib ) {
                result = attrib->Value();
                if ( i ) {
                        attrib->QueryIntValue( i );
                }
        }
        return result;
}

Here is the call graph for this function:

void TiXmlElement::ClearThis ( ) [protected]

Definition at line 560 of file tinyxml.cpp.

{
        Clear();
        while( attributeSet.First() )
        {
                TiXmlAttribute* node = attributeSet.First();
                attributeSet.Remove( node );
                delete node;
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

TiXmlNode * TiXmlElement::Clone ( ) const [virtual]

Creates a new Element and returns it - the returned element is a copy.

Implements TiXmlNode.

Definition at line 845 of file tinyxml.cpp.

{
        TiXmlElement* clone = new TiXmlElement( Value() );
        if ( !clone )
                return 0;

        CopyTo( clone );
        return clone;
}

Here is the call graph for this function:

void TiXmlElement::CopyTo ( TiXmlElement target) const [protected]

Definition at line 809 of file tinyxml.cpp.

{
        // superclass:
        TiXmlNode::CopyTo( target );

        // Element class: 
        // Clone the attributes, then clone the children.
        const TiXmlAttribute* attribute = 0;
        for(    attribute = attributeSet.First();
        attribute;
        attribute = attribute->Next() )
        {
                target->SetAttribute( attribute->Name(), attribute->Value() );
        }

        TiXmlNode* node = 0;
        for ( node = firstChild; node; node = node->NextSibling() )
        {
                target->LinkEndChild( node->Clone() );
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const TiXmlAttribute* TiXmlElement::FirstAttribute ( ) const [inline]

Access the first attribute in this element.

Definition at line 1077 of file tinyxml.h.

Here is the call graph for this function:

Here is the caller graph for this function:

TiXmlAttribute* TiXmlElement::FirstAttribute ( ) [inline]

Definition at line 1078 of file tinyxml.h.

{ return attributeSet.First(); }

Here is the call graph for this function:

const char * TiXmlElement::GetText ( ) const

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

If the first child of 'this' is a TiXmlText, 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 ".

WARNING: GetText() accesses a child node - don't become confused with the similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are safe type casts on the referenced node.

Definition at line 856 of file tinyxml.cpp.

{
        const TiXmlNode* child = this->FirstChild();
        if ( child ) {
                const TiXmlText* childText = child->ToText();
                if ( childText ) {
                        return childText->Value();
                }
        }
        return 0;
}

Here is the call graph for this function:

const TiXmlAttribute* TiXmlElement::LastAttribute ( ) const [inline]

Access the last attribute in this element.

Definition at line 1079 of file tinyxml.h.

Here is the call graph for this function:

TiXmlAttribute* TiXmlElement::LastAttribute ( ) [inline]

Definition at line 1080 of file tinyxml.h.

{ return attributeSet.Last(); }

Here is the call graph for this function:

void TiXmlElement::operator= ( const TiXmlElement base)

Definition at line 547 of file tinyxml.cpp.

{
        ClearThis();
        base.CopyTo( this );
}

Here is the call graph for this function:

const char * TiXmlElement::Parse ( const char *  p,
TiXmlParsingData data,
TiXmlEncoding  encoding 
) [virtual]

Implements TiXmlBase.

Definition at line 1043 of file tinyxmlparser.cpp.

{
        p = SkipWhiteSpace( p, encoding );
        TiXmlDocument* document = GetDocument();

        if ( !p || !*p )
        {
                if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding );
                return 0;
        }

        if ( data )
        {
                data->Stamp( p, encoding );
                location = data->Cursor();
        }

        if ( *p != '<' )
        {
                if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, p, data, encoding );
                return 0;
        }

        p = SkipWhiteSpace( p+1, encoding );

        // Read the name.
        const char* pErr = p;

    p = ReadName( p, &value, encoding );
        if ( !p || !*p )
        {
                if ( document ) document->SetError( TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding );
                return 0;
        }

    TIXML_STRING endTag ("</");
        endTag += value;

        // Check for and read attributes. Also look for an empty
        // tag or an end tag.
        while ( p && *p )
        {
                pErr = p;
                p = SkipWhiteSpace( p, encoding );
                if ( !p || !*p )
                {
                        if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
                        return 0;
                }
                if ( *p == '/' )
                {
                        ++p;
                        // Empty tag.
                        if ( *p  != '>' )
                        {
                                if ( document ) document->SetError( TIXML_ERROR_PARSING_EMPTY, p, data, encoding );             
                                return 0;
                        }
                        return (p+1);
                }
                else if ( *p == '>' )
                {
                        // Done with attributes (if there were any.)
                        // Read the value -- which can include other
                        // elements -- read the end tag, and return.
                        ++p;
                        p = ReadValue( p, data, encoding );             // Note this is an Element method, and will set the error if one happens.
                        if ( !p || !*p ) {
                                // We were looking for the end tag, but found nothing.
                                // Fix for [ 1663758 ] Failure to report error on bad XML
                                if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
                                return 0;
                        }

                        // We should find the end tag now
                        // note that:
                        // </foo > and
                        // </foo> 
                        // are both valid end tags.
                        if ( StringEqual( p, endTag.c_str(), false, encoding ) )
                        {
                                p += endTag.length();
                                p = SkipWhiteSpace( p, encoding );
                                if ( p && *p && *p == '>' ) {
                                        ++p;
                                        return p;
                                }
                                if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
                                return 0;
                        }
                        else
                        {
                                if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
                                return 0;
                        }
                }
                else
                {
                        // Try to read an attribute:
                        TiXmlAttribute* attrib = new TiXmlAttribute();
                        if ( !attrib )
                        {
                                return 0;
                        }

                        attrib->SetDocument( document );
                        pErr = p;
                        p = attrib->Parse( p, data, encoding );

                        if ( !p || !*p )
                        {
                                if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
                                delete attrib;
                                return 0;
                        }

                        // Handle the strange case of double attributes:
                        #ifdef TIXML_USE_STL
                        TiXmlAttribute* node = attributeSet.Find( attrib->NameTStr() );
                        #else
                        TiXmlAttribute* node = attributeSet.Find( attrib->Name() );
                        #endif
                        if ( node )
                        {
                                if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
                                delete attrib;
                                return 0;
                        }

                        attributeSet.Add( attrib );
                }
        }
        return p;
}

Here is the call graph for this function:

void TiXmlElement::Print ( FILE *  cfile,
int  depth 
) const [virtual]

All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.) Either or both cfile and str can be null.

This is a formatted print, and will insert tabs and newlines.

(For an unformatted stream, use the << operator.)

Implements TiXmlBase.

Definition at line 756 of file tinyxml.cpp.

{
        int i;
        assert( cfile );
        for ( i=0; i<depth; i++ ) {
                fprintf( cfile, "    " );
        }

        fprintf( cfile, "<%s", value.c_str() );

        const TiXmlAttribute* attrib;
        for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
        {
                fprintf( cfile, " " );
                attrib->Print( cfile, depth );
        }

        // There are 3 different formatting approaches:
        // 1) An element without children is printed as a <foo /> node
        // 2) An element with only a text child is printed as <foo> text </foo>
        // 3) An element with children is printed on multiple lines.
        TiXmlNode* node;
        if ( !firstChild )
        {
                fprintf( cfile, " />" );
        }
        else if ( firstChild == lastChild && firstChild->ToText() )
        {
                fprintf( cfile, ">" );
                firstChild->Print( cfile, depth + 1 );
                fprintf( cfile, "</%s>", value.c_str() );
        }
        else
        {
                fprintf( cfile, ">" );

                for ( node = firstChild; node; node=node->NextSibling() )
                {
                        if ( !node->ToText() )
                        {
                                fprintf( cfile, "\n" );
                        }
                        node->Print( cfile, depth+1 );
                }
                fprintf( cfile, "\n" );
                for( i=0; i<depth; ++i ) {
                        fprintf( cfile, "    " );
                }
                fprintf( cfile, "</%s>", value.c_str() );
        }
}

Here is the call graph for this function:

int TiXmlElement::QueryDoubleAttribute ( const char *  name,
double *  _value 
) const

QueryDoubleAttribute examines the attribute - see QueryIntAttribute().

Definition at line 676 of file tinyxml.cpp.

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        if ( !attrib )
                return TIXML_NO_ATTRIBUTE;
        return attrib->QueryDoubleValue( dval );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int TiXmlElement::QueryFloatAttribute ( const char *  name,
float *  _value 
) const [inline]

QueryFloatAttribute examines the attribute - see QueryIntAttribute().

Definition at line 989 of file tinyxml.h.

                                                                         {
                double d;
                int result = QueryDoubleAttribute( name, &d );
                if ( result == TIXML_SUCCESS ) {
                        *_value = (float)d;
                }
                return result;
        }

Here is the call graph for this function:

int TiXmlElement::QueryIntAttribute ( const char *  name,
int *  _value 
) const

QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking. If 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.

Definition at line 656 of file tinyxml.cpp.

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        if ( !attrib )
                return TIXML_NO_ATTRIBUTE;
        return attrib->QueryIntValue( ival );
}

Here is the call graph for this function:

const char * TiXmlElement::ReadValue ( const char *  in,
TiXmlParsingData prevData,
TiXmlEncoding  encoding 
) [protected]

Definition at line 1179 of file tinyxmlparser.cpp.

{
        TiXmlDocument* document = GetDocument();

        // Read in text and elements in any order.
        const char* pWithWhiteSpace = p;
        p = SkipWhiteSpace( p, encoding );

        while ( p && *p )
        {
                if ( *p != '<' )
                {
                        // Take what we have, make a text element.
                        TiXmlText* textNode = new TiXmlText( "" );

                        if ( !textNode )
                        {
                            return 0;
                        }

                        if ( TiXmlBase::IsWhiteSpaceCondensed() )
                        {
                                p = textNode->Parse( p, data, encoding );
                        }
                        else
                        {
                                // Special case: we want to keep the white space
                                // so that leading spaces aren't removed.
                                p = textNode->Parse( pWithWhiteSpace, data, encoding );
                        }

                        if ( !textNode->Blank() )
                                LinkEndChild( textNode );
                        else
                                delete textNode;
                } 
                else 
                {
                        // We hit a '<'
                        // Have we hit a new element or an end tag? This could also be
                        // a TiXmlText in the "CDATA" style.
                        if ( StringEqual( p, "</", false, encoding ) )
                        {
                                return p;
                        }
                        else
                        {
                                TiXmlNode* node = Identify( p, encoding );
                                if ( node )
                                {
                                        p = node->Parse( p, data, encoding );
                                        LinkEndChild( node );
                                }                               
                                else
                                {
                                        return 0;
                                }
                        }
                }
                pWithWhiteSpace = p;
                p = SkipWhiteSpace( p, encoding );
        }

        if ( !p )
        {
                if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding );
        }       
        return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TiXmlElement::RemoveAttribute ( const char *  name)

Deletes an attribute with the given name.

Definition at line 433 of file tinyxml.cpp.

{
    #ifdef TIXML_USE_STL
        TIXML_STRING str( name );
        TiXmlAttribute* node = attributeSet.Find( str );
        #else
        TiXmlAttribute* node = attributeSet.Find( name );
        #endif
        if ( node )
        {
                attributeSet.Remove( node );
                delete node;
        }
}

Here is the call graph for this function:

void TiXmlElement::SetAttribute ( const char *  name,
const char *  _value 
)

Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does.

Definition at line 736 of file tinyxml.cpp.

{
        TiXmlAttribute* attrib = attributeSet.FindOrCreate( cname );
        if ( attrib ) {
                attrib->SetValue( cvalue );
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TiXmlElement::SetAttribute ( const char *  name,
int  value 
)

Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does.

Definition at line 696 of file tinyxml.cpp.

{       
        TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
        if ( attrib ) {
                attrib->SetIntValue( val );
        }
}

Here is the call graph for this function:

void TiXmlElement::SetDoubleAttribute ( const char *  name,
double  value 
)

Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does.

Definition at line 716 of file tinyxml.cpp.

{       
        TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
        if ( attrib ) {
                attrib->SetDoubleValue( val );
        }
}

Here is the call graph for this function:

virtual TiXmlElement* TiXmlElement::ToElement ( ) [inline, virtual]

Cast to a more defined type. Will return null not of the requested type.

Reimplemented from TiXmlNode.

Definition at line 1127 of file tinyxml.h.

virtual const TiXmlElement* TiXmlElement::ToElement ( ) const [inline, virtual]

Cast to a more defined type. Will return null not of the requested type.

Reimplemented from TiXmlNode.

Definition at line 1126 of file tinyxml.h.


Member Data Documentation

Definition at line 1149 of file tinyxml.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines