osgEarth 2.1.1
|
#include <tinyxml.h>
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 TiXmlAttribute * | FirstAttribute () const |
Access the first attribute in this element. | |
TiXmlAttribute * | FirstAttribute () |
const TiXmlAttribute * | LastAttribute () const |
Access the last attribute in this element. | |
TiXmlAttribute * | LastAttribute () |
const char * | GetText () const |
virtual TiXmlNode * | Clone () 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 TiXmlElement * | ToElement () const |
Cast to a more defined type. Will return null not of the requested type. | |
virtual TiXmlElement * | ToElement () |
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 |
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.
TiXmlElement::TiXmlElement | ( | const char * | in_value | ) |
Construct an element.
Definition at line 521 of file tinyxml.cpp.
: TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) { firstChild = lastChild = 0; value = _value; }
TiXmlElement::TiXmlElement | ( | const TiXmlElement & | copy | ) |
Definition at line 539 of file tinyxml.cpp.
: TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) { firstChild = lastChild = 0; copy.CopyTo( this ); }
TiXmlElement::~TiXmlElement | ( | ) | [virtual] |
Definition at line 554 of file tinyxml.cpp.
{ ClearThis(); }
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 ); }
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; }
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; }
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; }
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; } }
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; }
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() ); } }
const TiXmlAttribute* TiXmlElement::FirstAttribute | ( | ) | const [inline] |
TiXmlAttribute* TiXmlElement::FirstAttribute | ( | ) | [inline] |
Definition at line 1078 of file tinyxml.h.
{ 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.
{ 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] |
TiXmlAttribute* TiXmlElement::LastAttribute | ( | ) | [inline] |
Definition at line 1080 of file tinyxml.h.
{ return attributeSet.Last(); }
void TiXmlElement::operator= | ( | const TiXmlElement & | base | ) |
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; }
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() ); } }
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 ); }
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; }
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 ); }
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; }
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; } }
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 ); } }
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 ); } }
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 ); } }
virtual TiXmlElement* TiXmlElement::ToElement | ( | ) | [inline, virtual] |
virtual const TiXmlElement* TiXmlElement::ToElement | ( | ) | const [inline, virtual] |
TiXmlAttributeSet TiXmlElement::attributeSet [private] |