Public Member Functions | Protected Member Functions

TiXmlElement Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlElement:
Inheritance graph
[legend]
Collaboration diagram for TiXmlElement:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TiXmlElement (const char *in_value)
 Construct an element.
 TiXmlElement (const std::string &_value)
 std::string constructor.
 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().
int QueryStringAttribute (const char *name, std::string *_value) const
 QueryStringAttribute examines the attribute - see QueryIntAttribute().
template<typename T >
int QueryValueAttribute (const std::string &name, T *outValue) const
int QueryValueAttribute (const std::string &name, std::string *outValue) const
void SetAttribute (const char *name, const char *_value)
const std::string * Attribute (const std::string &name) const
const std::string * Attribute (const std::string &name, int *i) const
const std::string * Attribute (const std::string &name, double *d) const
int QueryIntAttribute (const std::string &name, int *_value) const
int QueryDoubleAttribute (const std::string &name, double *_value) const
void SetAttribute (const std::string &name, const std::string &_value)
void SetAttribute (const std::string &name, int _value)
 STL std::string form.
void SetDoubleAttribute (const std::string &name, double value)
void SetAttribute (const char *name, int value)
void SetDoubleAttribute (const char *name, double value)
void RemoveAttribute (const char *name)
void RemoveAttribute (const std::string &name)
 STL std::string form.
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 ()
virtual void StreamIn (std::istream *in, TiXmlString *tag)
const char * ReadValue (const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)

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


Constructor & Destructor Documentation

TiXmlElement::TiXmlElement ( const char *  in_value )

Construct an element.

Definition at line 521 of file tinyxml.cpp.

References TiXmlNode::firstChild, TiXmlNode::lastChild, and TiXmlNode::value.

Referenced by Clone().

TiXmlElement::TiXmlElement ( const std::string &  _value )

std::string constructor.

Definition at line 530 of file tinyxml.cpp.

References TiXmlNode::firstChild, TiXmlNode::lastChild, and TiXmlNode::value.

TiXmlElement::TiXmlElement ( const TiXmlElement copy )

Definition at line 539 of file tinyxml.cpp.

References CopyTo(), TiXmlNode::firstChild, and TiXmlNode::lastChild.

TiXmlElement::~TiXmlElement (  ) [virtual]

Definition at line 554 of file tinyxml.cpp.

References ClearThis().

{
        ClearThis();
}

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.

References TiXmlAttributeSet::First(), TiXmlNode::FirstChild(), TiXmlNode::NextSibling(), TiXmlVisitor::VisitEnter(), and TiXmlVisitor::VisitExit().

{
        if ( visitor->VisitEnter( *this, attributeSet.First() ) ) 
        {
                for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
                {
                        if ( !node->Accept( visitor ) )
                                break;
                }
        }
        return visitor->VisitExit( *this );
}
const char * TiXmlElement::Attribute ( const char *  name ) const
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.

References TiXmlAttributeSet::Find(), TiXmlAttribute::QueryDoubleValue(), and TiXmlAttribute::Value().

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

        if ( attrib ) {
                result = attrib->Value();
                if ( d ) {
                        attrib->QueryDoubleValue( d );
                }
        }
        return result;
}
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.

References TiXmlAttributeSet::Find(), TiXmlAttribute::QueryIntValue(), and TiXmlAttribute::Value().

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

        if ( attrib ) {
                result = attrib->Value();
                if ( i ) {
                        attrib->QueryIntValue( i );
                }
        }
        return result;
}
const std::string * TiXmlElement::Attribute ( const std::string &  name ) const

Definition at line 582 of file tinyxml.cpp.

References TiXmlAttributeSet::Find(), and TiXmlAttribute::ValueStr().

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        if ( attrib )
                return &attrib->ValueStr();
        return 0;
}
const std::string * TiXmlElement::Attribute ( const std::string &  name,
int *  i 
) const

Definition at line 608 of file tinyxml.cpp.

References TiXmlAttributeSet::Find(), TiXmlAttribute::QueryIntValue(), and TiXmlAttribute::ValueStr().

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        const std::string* result = 0;

        if ( attrib ) {
                result = &attrib->ValueStr();
                if ( i ) {
                        attrib->QueryIntValue( i );
                }
        }
        return result;
}
const std::string * TiXmlElement::Attribute ( const std::string &  name,
double *  d 
) const

Definition at line 640 of file tinyxml.cpp.

References TiXmlAttributeSet::Find(), TiXmlAttribute::QueryDoubleValue(), and TiXmlAttribute::ValueStr().

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        const std::string* result = 0;

        if ( attrib ) {
                result = &attrib->ValueStr();
                if ( d ) {
                        attrib->QueryDoubleValue( d );
                }
        }
        return result;
}
void TiXmlElement::ClearThis (  ) [protected]

Definition at line 560 of file tinyxml.cpp.

References TiXmlNode::Clear(), TiXmlAttributeSet::First(), and TiXmlAttributeSet::Remove().

Referenced by operator=(), and ~TiXmlElement().

{
        Clear();
        while( attributeSet.First() )
        {
                TiXmlAttribute* node = attributeSet.First();
                attributeSet.Remove( node );
                delete node;
        }
}
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.

References CopyTo(), TiXmlElement(), and TiXmlNode::Value().

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

        CopyTo( clone );
        return clone;
}
void TiXmlElement::CopyTo ( TiXmlElement target ) const [protected]

Definition at line 809 of file tinyxml.cpp.

References TiXmlNode::Clone(), TiXmlAttributeSet::First(), TiXmlNode::firstChild, TiXmlNode::LinkEndChild(), TiXmlAttribute::Name(), TiXmlAttribute::Next(), TiXmlNode::NextSibling(), SetAttribute(), and TiXmlAttribute::Value().

Referenced by Clone(), operator=(), and TiXmlElement().

{
        // 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() );
        }
}
const TiXmlAttribute* TiXmlElement::FirstAttribute (  ) const [inline]

Access the first attribute in this element.

Definition at line 1082 of file tinyxml.h.

References TiXmlAttributeSet::First().

TiXmlAttribute* TiXmlElement::FirstAttribute (  ) [inline]

Definition at line 1083 of file tinyxml.h.

References TiXmlAttributeSet::First().

{ return attributeSet.First(); }
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.

References TiXmlNode::FirstChild(), TiXmlNode::ToText(), and TiXmlNode::Value().

Referenced by mitk::PointSetReader::GenerateData().

{
        const TiXmlNode* child = this->FirstChild();
        if ( child ) {
                const TiXmlText* childText = child->ToText();
                if ( childText ) {
                        return childText->Value();
                }
        }
        return 0;
}
const TiXmlAttribute* TiXmlElement::LastAttribute (  ) const [inline]

Access the last attribute in this element.

Definition at line 1084 of file tinyxml.h.

References TiXmlAttributeSet::Last().

TiXmlAttribute* TiXmlElement::LastAttribute (  ) [inline]

Definition at line 1085 of file tinyxml.h.

References TiXmlAttributeSet::Last().

{ return attributeSet.Last(); }
void TiXmlElement::operator= ( const TiXmlElement base )

Definition at line 547 of file tinyxml.cpp.

References ClearThis(), and CopyTo().

{
        ClearThis();
        base.CopyTo( this );
}
const char * TiXmlElement::Parse ( const char *  p,
TiXmlParsingData data,
TiXmlEncoding  encoding 
) [virtual]

Implements TiXmlBase.

Definition at line 1043 of file tinyxmlparser.cpp.

References TiXmlAttributeSet::Add(), TiXmlParsingData::Cursor(), TiXmlAttributeSet::Find(), TiXmlNode::GetDocument(), TiXmlBase::location, TiXmlAttribute::Name(), TiXmlAttribute::NameTStr(), TiXmlAttribute::Parse(), TiXmlBase::ReadName(), ReadValue(), TiXmlAttribute::SetDocument(), TiXmlDocument::SetError(), TiXmlBase::SkipWhiteSpace(), TiXmlParsingData::Stamp(), TiXmlBase::StringEqual(), TiXmlBase::TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, TiXmlBase::TIXML_ERROR_PARSING_ELEMENT, TiXmlBase::TIXML_ERROR_PARSING_EMPTY, TiXmlBase::TIXML_ERROR_READING_ATTRIBUTES, TiXmlBase::TIXML_ERROR_READING_END_TAG, TIXML_STRING, and TiXmlNode::value.

{
        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;
}
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.

References TiXmlAttributeSet::First(), TiXmlNode::firstChild, TiXmlNode::lastChild, TiXmlAttribute::Next(), TiXmlNode::NextSibling(), TiXmlBase::Print(), TiXmlNode::ToText(), and TiXmlNode::value.

{
        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() );
        }
}
int TiXmlElement::QueryDoubleAttribute ( const std::string &  name,
double *  _value 
) const

Definition at line 686 of file tinyxml.cpp.

References TiXmlAttributeSet::Find(), TiXmlAttribute::QueryDoubleValue(), and TIXML_NO_ATTRIBUTE.

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        if ( !attrib )
                return TIXML_NO_ATTRIBUTE;
        return attrib->QueryDoubleValue( dval );
}
int TiXmlElement::QueryDoubleAttribute ( const char *  name,
double *  _value 
) const
int TiXmlElement::QueryFloatAttribute ( const char *  name,
float *  _value 
) const [inline]
int TiXmlElement::QueryIntAttribute ( const std::string &  name,
int *  _value 
) const

Definition at line 666 of file tinyxml.cpp.

References TiXmlAttributeSet::Find(), TiXmlAttribute::QueryIntValue(), and TIXML_NO_ATTRIBUTE.

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        if ( !attrib )
                return TIXML_NO_ATTRIBUTE;
        return attrib->QueryIntValue( ival );
}
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.

References TiXmlAttributeSet::Find(), TiXmlAttribute::QueryIntValue(), and TIXML_NO_ATTRIBUTE.

Referenced by mitk::PropertyListDeserializer::Deserialize(), mitk::Point3iPropertyDeserializer::Deserialize(), mitk::LookupTablePropertyDeserializer::Deserialize(), mitk::IntPropertyDeserializer::Deserialize(), mitk::TransferFunctionPropertyDeserializer::DeserializeTransferFunction(), mitk::PlanarFigureReader::GenerateData(), mitk::SceneReader::LoadScene(), mitk::NavigationDataSequentialPlayer::ReadVersion1(), and mitk::NavigationDataPlayer::ReadVersion1().

{
        const TiXmlAttribute* attrib = attributeSet.Find( name );
        if ( !attrib )
                return TIXML_NO_ATTRIBUTE;
        return attrib->QueryIntValue( ival );
}
int TiXmlElement::QueryStringAttribute ( const char *  name,
std::string *  _value 
) const [inline]

QueryStringAttribute examines the attribute - see QueryIntAttribute().

Definition at line 1005 of file tinyxml.h.

References Attribute(), TIXML_NO_ATTRIBUTE, and TIXML_SUCCESS.

                                                                              {
                const char* cstr = Attribute( name );
                if ( cstr ) {
                        *_value = std::string( cstr );
                        return TIXML_SUCCESS;
                }
                return TIXML_NO_ATTRIBUTE;
        }
template<typename T >
int TiXmlElement::QueryValueAttribute ( const std::string &  name,
T *  outValue 
) const [inline]

Template form of the attribute query which will try to read the attribute into the specified type. Very easy, very powerful, but be careful to make sure to call this with the correct type.

NOTE: This method doesn't work correctly for 'string' types that contain spaces.

Returns:
TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE

Definition at line 1022 of file tinyxml.h.

References TiXmlAttributeSet::Find(), TIXML_NO_ATTRIBUTE, TIXML_SUCCESS, TIXML_WRONG_TYPE, and TiXmlAttribute::ValueStr().

        {
                const TiXmlAttribute* node = attributeSet.Find( name );
                if ( !node )
                        return TIXML_NO_ATTRIBUTE;

                std::stringstream sstream( node->ValueStr() );
                sstream >> *outValue;
                if ( !sstream.fail() )
                        return TIXML_SUCCESS;
                return TIXML_WRONG_TYPE;
        }
int TiXmlElement::QueryValueAttribute ( const std::string &  name,
std::string *  outValue 
) const [inline]

Definition at line 1035 of file tinyxml.h.

References TiXmlAttributeSet::Find(), TIXML_NO_ATTRIBUTE, TIXML_SUCCESS, and TiXmlAttribute::ValueStr().

        {
                const TiXmlAttribute* node = attributeSet.Find( name );
                if ( !node )
                        return TIXML_NO_ATTRIBUTE;
                *outValue = node->ValueStr();
                return TIXML_SUCCESS;
        }
const char * TiXmlElement::ReadValue ( const char *  in,
TiXmlParsingData prevData,
TiXmlEncoding  encoding 
) [protected]

Definition at line 1179 of file tinyxmlparser.cpp.

References TiXmlText::Blank(), TiXmlNode::GetDocument(), TiXmlNode::Identify(), TiXmlBase::IsWhiteSpaceCondensed(), TiXmlNode::LinkEndChild(), TiXmlBase::Parse(), TiXmlText::Parse(), TiXmlDocument::SetError(), TiXmlBase::SkipWhiteSpace(), TiXmlBase::StringEqual(), and TiXmlBase::TIXML_ERROR_READING_ELEMENT_VALUE.

Referenced by Parse().

{
        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;
}
void TiXmlElement::RemoveAttribute ( const char *  name )

Deletes an attribute with the given name.

Definition at line 433 of file tinyxml.cpp.

References TiXmlAttributeSet::Find(), TiXmlAttributeSet::Remove(), and TIXML_STRING.

{
    #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;
        }
}
void TiXmlElement::RemoveAttribute ( const std::string &  name ) [inline]

STL std::string form.

Definition at line 1079 of file tinyxml.h.

References RemoveAttribute().

Referenced by RemoveAttribute().

void TiXmlElement::SetAttribute ( const char *  name,
const char *  _value 
)
void TiXmlElement::SetAttribute ( const std::string &  name,
int  _value 
)

STL std::string form.

Definition at line 706 of file tinyxml.cpp.

References TiXmlAttributeSet::FindOrCreate(), and TiXmlAttribute::SetIntValue().

{       
        TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
        if ( attrib ) {
                attrib->SetIntValue( val );
        }
}
void TiXmlElement::SetAttribute ( const std::string &  name,
const std::string &  _value 
)

STL std::string form.

Definition at line 746 of file tinyxml.cpp.

References TiXmlAttributeSet::FindOrCreate(), and TiXmlAttribute::SetValue().

{
        TiXmlAttribute* attrib = attributeSet.FindOrCreate( _name );
        if ( attrib ) {
                attrib->SetValue( _value );
        }
}
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.

References TiXmlAttributeSet::FindOrCreate(), and TiXmlAttribute::SetIntValue().

{       
        TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
        if ( attrib ) {
                attrib->SetIntValue( val );
        }
}
void TiXmlElement::SetDoubleAttribute ( const std::string &  name,
double  value 
)
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.

References TiXmlAttributeSet::FindOrCreate(), and TiXmlAttribute::SetDoubleValue().

{       
        TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
        if ( attrib ) {
                attrib->SetDoubleValue( val );
        }
}
void TiXmlElement::StreamIn ( std::istream *  in,
TiXmlString *  tag 
) [protected, virtual]

Implements TiXmlNode.

Definition at line 903 of file tinyxmlparser.cpp.

References TiXmlNode::GetDocument(), TiXmlNode::Identify(), int(), TiXmlBase::IsWhiteSpace(), TiXmlDocument::SetError(), TiXmlNode::StreamIn(), TiXmlText::StreamIn(), TiXmlBase::StreamWhiteSpace(), TIXML_DEFAULT_ENCODING, TIXML_ENCODING_UNKNOWN, and TiXmlBase::TIXML_ERROR_EMBEDDED_NULL.

{
        // We're called with some amount of pre-parsing. That is, some of "this"
        // element is in "tag". Go ahead and stream to the closing ">"
        while( in->good() )
        {
                int c = in->get();
                if ( c <= 0 )
                {
                        TiXmlDocument* document = GetDocument();
                        if ( document )
                                document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
                        return;
                }
                (*tag) += (char) c ;
                
                if ( c == '>' )
                        break;
        }

        if ( tag->length() < 3 ) return;

        // Okay...if we are a "/>" tag, then we're done. We've read a complete tag.
        // If not, identify and stream.

        if (    tag->at( tag->length() - 1 ) == '>' 
                 && tag->at( tag->length() - 2 ) == '/' )
        {
                // All good!
                return;
        }
        else if ( tag->at( tag->length() - 1 ) == '>' )
        {
                // There is more. Could be:
                //              text
                //              cdata text (which looks like another node)
                //              closing tag
                //              another node.
                for ( ;; )
                {
                        StreamWhiteSpace( in, tag );

                        // Do we have text?
                        if ( in->good() && in->peek() != '<' ) 
                        {
                                // Yep, text.
                                TiXmlText text( "" );
                                text.StreamIn( in, tag );

                                // What follows text is a closing tag or another node.
                                // Go around again and figure it out.
                                continue;
                        }

                        // We now have either a closing tag...or another node.
                        // We should be at a "<", regardless.
                        if ( !in->good() ) return;
                        assert( in->peek() == '<' );
                        int tagIndex = (int) tag->length();

                        bool closingTag = false;
                        bool firstCharFound = false;

                        for( ;; )
                        {
                                if ( !in->good() )
                                        return;

                                int c = in->peek();
                                if ( c <= 0 )
                                {
                                        TiXmlDocument* document = GetDocument();
                                        if ( document )
                                                document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
                                        return;
                                }
                                
                                if ( c == '>' )
                                        break;

                                *tag += (char) c;
                                in->get();

                                // Early out if we find the CDATA id.
                                if ( c == '[' && tag->size() >= 9 )
                                {
                                        size_t len = tag->size();
                                        const char* start = tag->c_str() + len - 9;
                                        if ( strcmp( start, "<![CDATA[" ) == 0 ) {
                                                assert( !closingTag );
                                                break;
                                        }
                                }

                                if ( !firstCharFound && c != '<' && !IsWhiteSpace( c ) )
                                {
                                        firstCharFound = true;
                                        if ( c == '/' )
                                                closingTag = true;
                                }
                        }
                        // If it was a closing tag, then read in the closing '>' to clean up the input stream.
                        // If it was not, the streaming will be done by the tag.
                        if ( closingTag )
                        {
                                if ( !in->good() )
                                        return;

                                int c = in->get();
                                if ( c <= 0 )
                                {
                                        TiXmlDocument* document = GetDocument();
                                        if ( document )
                                                document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
                                        return;
                                }
                                assert( c == '>' );
                                *tag += (char) c;

                                // We are done, once we've found our closing tag.
                                return;
                        }
                        else
                        {
                                // If not a closing tag, id it, and stream.
                                const char* tagloc = tag->c_str() + tagIndex;
                                TiXmlNode* node = Identify( tagloc, TIXML_DEFAULT_ENCODING );
                                if ( !node )
                                        return;
                                node->StreamIn( in, tag );
                                delete node;
                                node = 0;

                                // No return: go around from the beginning: text, closing tag, or node.
                        }
                }
        }
}
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 1131 of file tinyxml.h.

Referenced by mitk::PointSetReader::GenerateData(), mitk::PointSetReader::ReadPoint(), and mitk::NavigationDataPlayer::ReadVersion1().

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


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