#include <OBTtinyxml.h>
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 |
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. | |
const char * | 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. | |
const char * | 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. | |
int | QueryIntAttribute (const char *name, int *_value) const |
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking. | |
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(). | |
template<typename T> | |
int | QueryValueAttribute (const std::string &name, T *outValue) const |
Template form of the attribute query which will try to read the attribute into the specified type. | |
void | SetAttribute (const char *name, const char *_value) |
Sets an attribute of name to a given 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) |
STL std::string form. | |
void | SetAttribute (const std::string &name, int _value) |
void | SetAttribute (const char *name, int value) |
Sets an attribute of name to a given value. | |
void | SetDoubleAttribute (const char *name, double value) |
Sets an attribute of name to a given value. | |
void | RemoveAttribute (const char *name) |
Deletes an attribute with the given name. | |
void | RemoveAttribute (const std::string &name) |
STL std::string form. | |
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 |
Convenience function for easy access to the text inside an element. | |
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 |
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode. | |
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 |
Walk the XML tree visiting this node and all of its children. | |
Protected Member Functions | |
void | CopyTo (TiXmlElement *target) const |
void | ClearThis () |
virtual void | StreamIn (std::istream *in, TIXML_STRING *tag) |
const char * | ReadValue (const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding) |
Private Attributes | |
TiXmlAttributeSet | attributeSet |
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 949 of file tiny/tmp/OBTtinyxml.h.
xmlTiny::TiXmlElement::TiXmlElement | ( | const char * | in_value | ) |
Construct an element.
Definition at line 507 of file tiny/tmp/OBTtinyxml.cpp.
References xmlTiny::TiXmlNode::firstChild, xmlTiny::TiXmlNode::lastChild, and xmlTiny::TiXmlNode::value.
Referenced by Clone().
00508 : TiXmlNode( TiXmlNode::ELEMENT ) 00509 { 00510 firstChild = lastChild = 0; 00511 value = _value; 00512 }
xmlTiny::TiXmlElement::TiXmlElement | ( | const std::string & | _value | ) |
std::string constructor.
xmlTiny::TiXmlElement::TiXmlElement | ( | const TiXmlElement & | copy | ) |
Definition at line 525 of file tiny/tmp/OBTtinyxml.cpp.
References CopyTo(), xmlTiny::TiXmlNode::firstChild, and xmlTiny::TiXmlNode::lastChild.
00526 : TiXmlNode( TiXmlNode::ELEMENT ) 00527 { 00528 firstChild = lastChild = 0; 00529 copy.CopyTo( this ); 00530 }
xmlTiny::TiXmlElement::~TiXmlElement | ( | ) | [virtual] |
Definition at line 540 of file tiny/tmp/OBTtinyxml.cpp.
References ClearThis().
00541 { 00542 ClearThis(); 00543 }
void xmlTiny::TiXmlElement::operator= | ( | const TiXmlElement & | base | ) |
Definition at line 533 of file tiny/tmp/OBTtinyxml.cpp.
References ClearThis(), and CopyTo().
00534 { 00535 ClearThis(); 00536 base.CopyTo( this ); 00537 }
const char * xmlTiny::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 558 of file tiny/tmp/OBTtinyxml.cpp.
References attributeSet, xmlTiny::TiXmlAttributeSet::Find(), and xmlTiny::TiXmlAttribute::Value().
Referenced by Attribute().
00559 { 00560 const TiXmlAttribute* node = attributeSet.Find( name ); 00561 if ( node ) 00562 return node->Value(); 00563 return 0; 00564 }
const char * xmlTiny::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 578 of file tiny/tmp/OBTtinyxml.cpp.
References Attribute().
00579 { 00580 const char* s = Attribute( name ); 00581 if ( i ) 00582 { 00583 if ( s ) { 00584 *i = atoi( s ); 00585 } 00586 else { 00587 *i = 0; 00588 } 00589 } 00590 return s; 00591 }
const char * xmlTiny::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 612 of file tiny/tmp/OBTtinyxml.cpp.
References Attribute().
00613 { 00614 const char* s = Attribute( name ); 00615 if ( d ) 00616 { 00617 if ( s ) { 00618 *d = atof( s ); 00619 } 00620 else { 00621 *d = 0; 00622 } 00623 } 00624 return s; 00625 }
int xmlTiny::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 646 of file tiny/tmp/OBTtinyxml.cpp.
References attributeSet, xmlTiny::TiXmlAttributeSet::Find(), xmlTiny::TiXmlAttribute::QueryIntValue(), and xmlTiny::TIXML_NO_ATTRIBUTE.
00647 { 00648 const TiXmlAttribute* node = attributeSet.Find( name ); 00649 if ( !node ) 00650 return TIXML_NO_ATTRIBUTE; 00651 return node->QueryIntValue( ival ); 00652 }
int xmlTiny::TiXmlElement::QueryDoubleAttribute | ( | const char * | name, | |
double * | _value | |||
) | const |
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
Definition at line 666 of file tiny/tmp/OBTtinyxml.cpp.
References attributeSet, xmlTiny::TiXmlAttributeSet::Find(), xmlTiny::TiXmlAttribute::QueryDoubleValue(), and xmlTiny::TIXML_NO_ATTRIBUTE.
Referenced by QueryFloatAttribute().
00667 { 00668 const TiXmlAttribute* node = attributeSet.Find( name ); 00669 if ( !node ) 00670 return TIXML_NO_ATTRIBUTE; 00671 return node->QueryDoubleValue( dval ); 00672 }
int xmlTiny::TiXmlElement::QueryFloatAttribute | ( | const char * | name, | |
float * | _value | |||
) | const [inline] |
QueryFloatAttribute examines the attribute - see QueryIntAttribute().
Definition at line 998 of file tiny/tmp/OBTtinyxml.h.
References QueryDoubleAttribute(), and xmlTiny::TIXML_SUCCESS.
00998 { 00999 double d; 01000 int result = QueryDoubleAttribute( name, &d ); 01001 if ( result == TIXML_SUCCESS ) { 01002 *_value = (float)d; 01003 } 01004 return result; 01005 }
int xmlTiny::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.
Definition at line 1016 of file tiny/tmp/OBTtinyxml.h.
References attributeSet, xmlTiny::TiXmlAttributeSet::Find(), xmlTiny::TIXML_NO_ATTRIBUTE, xmlTiny::TIXML_SUCCESS, xmlTiny::TIXML_WRONG_TYPE, and xmlTiny::TiXmlAttribute::ValueStr().
01017 { 01018 const TiXmlAttribute* node = attributeSet.Find( name ); 01019 if ( !node ) 01020 return TIXML_NO_ATTRIBUTE; 01021 01022 std::stringstream sstream( node->ValueStr() ); 01023 sstream >> *outValue; 01024 if ( !sstream.fail() ) 01025 return TIXML_SUCCESS; 01026 return TIXML_WRONG_TYPE; 01027 }
void xmlTiny::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 720 of file tiny/tmp/OBTtinyxml.cpp.
References xmlTiny::TiXmlAttributeSet::Add(), attributeSet, xmlTiny::TiXmlAttributeSet::Find(), xmlTiny::TiXmlNode::GetDocument(), xmlTiny::TiXmlDocument::SetError(), xmlTiny::TiXmlAttribute::SetValue(), xmlTiny::TIXML_ENCODING_UNKNOWN, xmlTiny::TiXmlBase::TIXML_ERROR_OUT_OF_MEMORY, and TIXML_STRING.
Referenced by CopyTo(), SetAttribute(), and SetDoubleAttribute().
00721 { 00722 #ifdef TIXML_USE_STL 00723 TIXML_STRING _name( cname ); 00724 TIXML_STRING _value( cvalue ); 00725 #else 00726 const char* _name = cname; 00727 const char* _value = cvalue; 00728 #endif 00729 00730 TiXmlAttribute* node = attributeSet.Find( _name ); 00731 if ( node ) 00732 { 00733 node->SetValue( _value ); 00734 return; 00735 } 00736 00737 TiXmlAttribute* attrib = new TiXmlAttribute( cname, cvalue ); 00738 if ( attrib ) 00739 { 00740 attributeSet.Add( attrib ); 00741 } 00742 else 00743 { 00744 TiXmlDocument* document = GetDocument(); 00745 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN ); 00746 } 00747 }
const std::string* xmlTiny::TiXmlElement::Attribute | ( | const std::string & | name | ) | const |
const std::string* xmlTiny::TiXmlElement::Attribute | ( | const std::string & | name, | |
int * | i | |||
) | const |
const std::string* xmlTiny::TiXmlElement::Attribute | ( | const std::string & | name, | |
double * | d | |||
) | const |
int xmlTiny::TiXmlElement::QueryIntAttribute | ( | const std::string & | name, | |
int * | _value | |||
) | const |
int xmlTiny::TiXmlElement::QueryDoubleAttribute | ( | const std::string & | name, | |
double * | _value | |||
) | const |
void xmlTiny::TiXmlElement::SetAttribute | ( | const std::string & | name, | |
const std::string & | _value | |||
) |
STL std::string form.
STL std::string form.
void xmlTiny::TiXmlElement::SetAttribute | ( | const std::string & | name, | |
int | _value | |||
) |
void xmlTiny::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 686 of file tiny/tmp/OBTtinyxml.cpp.
References SetAttribute().
00687 { 00688 char buf[64]; 00689 #if defined(TIXML_SNPRINTF) 00690 TIXML_SNPRINTF( buf, sizeof(buf), "%d", val ); 00691 #else 00692 sprintf( buf, "%d", val ); 00693 #endif 00694 SetAttribute( name, buf ); 00695 }
void xmlTiny::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 708 of file tiny/tmp/OBTtinyxml.cpp.
References SetAttribute().
00709 { 00710 char buf[256]; 00711 #if defined(TIXML_SNPRINTF) 00712 TIXML_SNPRINTF( buf, sizeof(buf), "%f", val ); 00713 #else 00714 sprintf( buf, "%f", val ); 00715 #endif 00716 SetAttribute( name, buf ); 00717 }
void xmlTiny::TiXmlElement::RemoveAttribute | ( | const char * | name | ) |
Deletes an attribute with the given name.
Definition at line 419 of file tiny/tmp/OBTtinyxml.cpp.
References attributeSet, xmlTiny::TiXmlAttributeSet::Find(), xmlTiny::TiXmlAttributeSet::Remove(), and TIXML_STRING.
Referenced by RemoveAttribute().
00420 { 00421 #ifdef TIXML_USE_STL 00422 TIXML_STRING str( name ); 00423 TiXmlAttribute* node = attributeSet.Find( str ); 00424 #else 00425 TiXmlAttribute* node = attributeSet.Find( name ); 00426 #endif 00427 if ( node ) 00428 { 00429 attributeSet.Remove( node ); 00430 delete node; 00431 } 00432 }
void xmlTiny::TiXmlElement::RemoveAttribute | ( | const std::string & | name | ) | [inline] |
STL std::string form.
Definition at line 1077 of file tiny/tmp/OBTtinyxml.h.
References RemoveAttribute().
const TiXmlAttribute* xmlTiny::TiXmlElement::FirstAttribute | ( | ) | const [inline] |
Access the first attribute in this element.
Definition at line 1080 of file tiny/tmp/OBTtinyxml.h.
References attributeSet, and xmlTiny::TiXmlAttributeSet::First().
TiXmlAttribute* xmlTiny::TiXmlElement::FirstAttribute | ( | ) | [inline] |
Definition at line 1081 of file tiny/tmp/OBTtinyxml.h.
References attributeSet, and xmlTiny::TiXmlAttributeSet::First().
01081 { return attributeSet.First(); }
const TiXmlAttribute* xmlTiny::TiXmlElement::LastAttribute | ( | ) | const [inline] |
Access the last attribute in this element.
Definition at line 1082 of file tiny/tmp/OBTtinyxml.h.
References attributeSet, and xmlTiny::TiXmlAttributeSet::Last().
TiXmlAttribute* xmlTiny::TiXmlElement::LastAttribute | ( | ) | [inline] |
Definition at line 1083 of file tiny/tmp/OBTtinyxml.h.
References attributeSet, and xmlTiny::TiXmlAttributeSet::Last().
01083 { return attributeSet.Last(); }
const char * xmlTiny::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>
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 874 of file tiny/tmp/OBTtinyxml.cpp.
References xmlTiny::TiXmlNode::FirstChild(), xmlTiny::TiXmlNode::ToText(), and xmlTiny::TiXmlNode::Value().
00875 { 00876 const TiXmlNode* child = this->FirstChild(); 00877 if ( child ) { 00878 const TiXmlText* childText = child->ToText(); 00879 if ( childText ) { 00880 return childText->Value(); 00881 } 00882 } 00883 return 0; 00884 }
TiXmlNode * xmlTiny::TiXmlElement::Clone | ( | ) | const [virtual] |
Creates a new Element and returns it - the returned element is a copy.
Implements xmlTiny::TiXmlNode.
Definition at line 863 of file tiny/tmp/OBTtinyxml.cpp.
References CopyTo(), TiXmlElement(), and xmlTiny::TiXmlNode::Value().
00864 { 00865 TiXmlElement* clone = new TiXmlElement( Value() ); 00866 if ( !clone ) 00867 return 0; 00868 00869 CopyTo( clone ); 00870 return clone; 00871 }
void xmlTiny::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 xmlTiny::TiXmlBase.
Definition at line 774 of file tiny/tmp/OBTtinyxml.cpp.
References attributeSet, xmlTiny::TiXmlAttributeSet::First(), xmlTiny::TiXmlNode::firstChild, xmlTiny::TiXmlNode::lastChild, xmlTiny::TiXmlAttribute::Next(), xmlTiny::TiXmlNode::NextSibling(), xmlTiny::TiXmlBase::Print(), xmlTiny::TiXmlNode::ToText(), and xmlTiny::TiXmlNode::value.
00775 { 00776 int i; 00777 assert( cfile ); 00778 for ( i=0; i<depth; i++ ) { 00779 fprintf( cfile, " " ); 00780 } 00781 00782 fprintf( cfile, "<%s", value.c_str() ); 00783 00784 const TiXmlAttribute* attrib; 00785 for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) 00786 { 00787 fprintf( cfile, " " ); 00788 attrib->Print( cfile, depth ); 00789 } 00790 00791 // There are 3 different formatting approaches: 00792 // 1) An element without children is printed as a <foo /> node 00793 // 2) An element with only a text child is printed as <foo> text </foo> 00794 // 3) An element with children is printed on multiple lines. 00795 TiXmlNode* node; 00796 if ( !firstChild ) 00797 { 00798 fprintf( cfile, " />" ); 00799 } 00800 else if ( firstChild == lastChild && firstChild->ToText() ) 00801 { 00802 fprintf( cfile, ">" ); 00803 firstChild->Print( cfile, depth + 1 ); 00804 fprintf( cfile, "</%s>", value.c_str() ); 00805 } 00806 else 00807 { 00808 fprintf( cfile, ">" ); 00809 00810 for ( node = firstChild; node; node=node->NextSibling() ) 00811 { 00812 if ( !node->ToText() ) 00813 { 00814 fprintf( cfile, "\n" ); 00815 } 00816 node->Print( cfile, depth+1 ); 00817 } 00818 fprintf( cfile, "\n" ); 00819 for( i=0; i<depth; ++i ) { 00820 fprintf( cfile, " " ); 00821 } 00822 fprintf( cfile, "</%s>", value.c_str() ); 00823 } 00824 }
const char * xmlTiny::TiXmlElement::Parse | ( | const char * | p, | |
TiXmlParsingData * | data, | |||
TiXmlEncoding | encoding | |||
) | [virtual] |
Implements xmlTiny::TiXmlBase.
Definition at line 1051 of file tiny/tmp/OBTtinyxmlparser.cpp.
References xmlTiny::TiXmlAttributeSet::Add(), attributeSet, xmlTiny::TiXmlParsingData::Cursor(), xmlTiny::TiXmlAttributeSet::Find(), xmlTiny::TiXmlNode::GetDocument(), xmlTiny::TiXmlBase::location, xmlTiny::TiXmlAttribute::Name(), xmlTiny::TiXmlAttribute::NameTStr(), xmlTiny::TiXmlAttribute::Parse(), xmlTiny::TiXmlBase::ReadName(), ReadValue(), xmlTiny::TiXmlAttribute::SetDocument(), xmlTiny::TiXmlDocument::SetError(), xmlTiny::TiXmlAttribute::SetValue(), xmlTiny::TiXmlBase::SkipWhiteSpace(), xmlTiny::TiXmlParsingData::Stamp(), xmlTiny::TiXmlBase::StringEqual(), xmlTiny::TiXmlBase::TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, xmlTiny::TiXmlBase::TIXML_ERROR_OUT_OF_MEMORY, xmlTiny::TiXmlBase::TIXML_ERROR_PARSING_ELEMENT, xmlTiny::TiXmlBase::TIXML_ERROR_PARSING_EMPTY, xmlTiny::TiXmlBase::TIXML_ERROR_READING_ATTRIBUTES, xmlTiny::TiXmlBase::TIXML_ERROR_READING_END_TAG, TIXML_STRING, xmlTiny::TiXmlAttribute::Value(), and xmlTiny::TiXmlNode::value.
01052 { 01053 p = SkipWhiteSpace( p, encoding ); 01054 TiXmlDocument* document = GetDocument(); 01055 01056 if ( !p || !*p ) 01057 { 01058 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding ); 01059 return 0; 01060 } 01061 01062 if ( data ) 01063 { 01064 data->Stamp( p, encoding ); 01065 location = data->Cursor(); 01066 } 01067 01068 if ( *p != '<' ) 01069 { 01070 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, p, data, encoding ); 01071 return 0; 01072 } 01073 01074 p = SkipWhiteSpace( p+1, encoding ); 01075 01076 // Read the name. 01077 const char* pErr = p; 01078 01079 p = ReadName( p, &value, encoding ); 01080 if ( !p || !*p ) 01081 { 01082 if ( document ) document->SetError( TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding ); 01083 return 0; 01084 } 01085 01086 TIXML_STRING endTag ("</"); 01087 endTag += value; 01088 endTag += ">"; 01089 01090 // Check for and read attributes. Also look for an empty 01091 // tag or an end tag. 01092 while ( p && *p ) 01093 { 01094 pErr = p; 01095 p = SkipWhiteSpace( p, encoding ); 01096 if ( !p || !*p ) 01097 { 01098 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); 01099 return 0; 01100 } 01101 if ( *p == '/' ) 01102 { 01103 ++p; 01104 // Empty tag. 01105 if ( *p != '>' ) 01106 { 01107 if ( document ) document->SetError( TIXML_ERROR_PARSING_EMPTY, p, data, encoding ); 01108 return 0; 01109 } 01110 return (p+1); 01111 } 01112 else if ( *p == '>' ) 01113 { 01114 // Done with attributes (if there were any.) 01115 // Read the value -- which can include other 01116 // elements -- read the end tag, and return. 01117 ++p; 01118 p = ReadValue( p, data, encoding ); // Note this is an Element method, and will set the error if one happens. 01119 if ( !p || !*p ) { 01120 // We were looking for the end tag, but found nothing. 01121 // Fix for [ 1663758 ] Failure to report error on bad XML 01122 if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding ); 01123 return 0; 01124 } 01125 01126 // We should find the end tag now 01127 if ( StringEqual( p, endTag.c_str(), false, encoding ) ) 01128 { 01129 p += endTag.length(); 01130 return p; 01131 } 01132 else 01133 { 01134 if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding ); 01135 return 0; 01136 } 01137 } 01138 else 01139 { 01140 // Try to read an attribute: 01141 TiXmlAttribute* attrib = new TiXmlAttribute(); 01142 if ( !attrib ) 01143 { 01144 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, pErr, data, encoding ); 01145 return 0; 01146 } 01147 01148 attrib->SetDocument( document ); 01149 pErr = p; 01150 p = attrib->Parse( p, data, encoding ); 01151 01152 if ( !p || !*p ) 01153 { 01154 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding ); 01155 delete attrib; 01156 return 0; 01157 } 01158 01159 // Handle the strange case of double attributes: 01160 #ifdef TIXML_USE_STL 01161 TiXmlAttribute* node = attributeSet.Find( attrib->NameTStr() ); 01162 #else 01163 TiXmlAttribute* node = attributeSet.Find( attrib->Name() ); 01164 #endif 01165 if ( node ) 01166 { 01167 node->SetValue( attrib->Value() ); 01168 delete attrib; 01169 return 0; 01170 } 01171 01172 attributeSet.Add( attrib ); 01173 } 01174 } 01175 return p; 01176 }
virtual const TiXmlElement* xmlTiny::TiXmlElement::ToElement | ( | ) | const [inline, virtual] |
Cast to a more defined type. Will return null not of the requested type.
Reimplemented from xmlTiny::TiXmlNode.
Definition at line 1129 of file tiny/tmp/OBTtinyxml.h.
virtual TiXmlElement* xmlTiny::TiXmlElement::ToElement | ( | ) | [inline, virtual] |
Cast to a more defined type. Will return null not of the requested type.
Reimplemented from xmlTiny::TiXmlNode.
Definition at line 1130 of file tiny/tmp/OBTtinyxml.h.
bool xmlTiny::TiXmlElement::Accept | ( | TiXmlVisitor * | visitor | ) | const [virtual] |
Walk the XML tree visiting this node and all of its children.
Implements xmlTiny::TiXmlNode.
Definition at line 849 of file tiny/tmp/OBTtinyxml.cpp.
References attributeSet, xmlTiny::TiXmlAttributeSet::First(), xmlTiny::TiXmlNode::FirstChild(), xmlTiny::TiXmlVisitor::VisitEnter(), and xmlTiny::TiXmlVisitor::VisitExit().
00850 { 00851 if ( visitor->VisitEnter( *this, attributeSet.First() ) ) 00852 { 00853 for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) 00854 { 00855 if ( !node->Accept( visitor ) ) 00856 break; 00857 } 00858 } 00859 return visitor->VisitExit( *this ); 00860 }
void xmlTiny::TiXmlElement::CopyTo | ( | TiXmlElement * | target | ) | const [protected] |
Definition at line 827 of file tiny/tmp/OBTtinyxml.cpp.
References attributeSet, xmlTiny::TiXmlNode::Clone(), xmlTiny::TiXmlNode::CopyTo(), xmlTiny::TiXmlAttributeSet::First(), xmlTiny::TiXmlNode::firstChild, xmlTiny::TiXmlNode::LinkEndChild(), xmlTiny::TiXmlAttribute::Name(), xmlTiny::TiXmlAttribute::Next(), xmlTiny::TiXmlNode::NextSibling(), SetAttribute(), and xmlTiny::TiXmlAttribute::Value().
Referenced by Clone(), operator=(), and TiXmlElement().
00828 { 00829 // superclass: 00830 TiXmlNode::CopyTo( target ); 00831 00832 // Element class: 00833 // Clone the attributes, then clone the children. 00834 const TiXmlAttribute* attribute = 0; 00835 for( attribute = attributeSet.First(); 00836 attribute; 00837 attribute = attribute->Next() ) 00838 { 00839 target->SetAttribute( attribute->Name(), attribute->Value() ); 00840 } 00841 00842 TiXmlNode* node = 0; 00843 for ( node = firstChild; node; node = node->NextSibling() ) 00844 { 00845 target->LinkEndChild( node->Clone() ); 00846 } 00847 }
void xmlTiny::TiXmlElement::ClearThis | ( | ) | [protected] |
Definition at line 546 of file tiny/tmp/OBTtinyxml.cpp.
References attributeSet, xmlTiny::TiXmlNode::Clear(), xmlTiny::TiXmlAttributeSet::First(), and xmlTiny::TiXmlAttributeSet::Remove().
Referenced by operator=(), and ~TiXmlElement().
00547 { 00548 Clear(); 00549 while( attributeSet.First() ) 00550 { 00551 TiXmlAttribute* node = attributeSet.First(); 00552 attributeSet.Remove( node ); 00553 delete node; 00554 } 00555 }
virtual void xmlTiny::TiXmlElement::StreamIn | ( | std::istream * | in, | |
TIXML_STRING * | tag | |||
) | [protected, virtual] |
Implements xmlTiny::TiXmlNode.
const char * xmlTiny::TiXmlElement::ReadValue | ( | const char * | in, | |
TiXmlParsingData * | prevData, | |||
TiXmlEncoding | encoding | |||
) | [protected] |
Definition at line 1179 of file tiny/tmp/OBTtinyxmlparser.cpp.
References xmlTiny::TiXmlText::Blank(), xmlTiny::TiXmlNode::GetDocument(), xmlTiny::TiXmlNode::Identify(), xmlTiny::TiXmlBase::IsWhiteSpaceCondensed(), xmlTiny::TiXmlNode::LinkEndChild(), xmlTiny::TiXmlBase::Parse(), xmlTiny::TiXmlText::Parse(), xmlTiny::TiXmlDocument::SetError(), xmlTiny::TiXmlBase::SkipWhiteSpace(), xmlTiny::TiXmlBase::StringEqual(), xmlTiny::TiXmlBase::TIXML_ERROR_OUT_OF_MEMORY, and xmlTiny::TiXmlBase::TIXML_ERROR_READING_ELEMENT_VALUE.
Referenced by Parse().
01180 { 01181 TiXmlDocument* document = GetDocument(); 01182 01183 // Read in text and elements in any order. 01184 const char* pWithWhiteSpace = p; 01185 p = SkipWhiteSpace( p, encoding ); 01186 01187 while ( p && *p ) 01188 { 01189 if ( *p != '<' ) 01190 { 01191 // Take what we have, make a text element. 01192 TiXmlText* textNode = new TiXmlText( "" ); 01193 01194 if ( !textNode ) 01195 { 01196 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding ); 01197 return 0; 01198 } 01199 01200 if ( TiXmlBase::IsWhiteSpaceCondensed() ) 01201 { 01202 p = textNode->Parse( p, data, encoding ); 01203 } 01204 else 01205 { 01206 // Special case: we want to keep the white space 01207 // so that leading spaces aren't removed. 01208 p = textNode->Parse( pWithWhiteSpace, data, encoding ); 01209 } 01210 01211 if ( !textNode->Blank() ) 01212 LinkEndChild( textNode ); 01213 else 01214 delete textNode; 01215 } 01216 else 01217 { 01218 // We hit a '<' 01219 // Have we hit a new element or an end tag? This could also be 01220 // a TiXmlText in the "CDATA" style. 01221 if ( StringEqual( p, "</", false, encoding ) ) 01222 { 01223 return p; 01224 } 01225 else 01226 { 01227 TiXmlNode* node = Identify( p, encoding ); 01228 if ( node ) 01229 { 01230 p = node->Parse( p, data, encoding ); 01231 LinkEndChild( node ); 01232 } 01233 else 01234 { 01235 return 0; 01236 } 01237 } 01238 } 01239 pWithWhiteSpace = p; 01240 p = SkipWhiteSpace( p, encoding ); 01241 } 01242 01243 if ( !p ) 01244 { 01245 if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding ); 01246 } 01247 return p; 01248 }
Definition at line 1153 of file tiny/tmp/OBTtinyxml.h.
Referenced by Accept(), Attribute(), ClearThis(), CopyTo(), FirstAttribute(), LastAttribute(), Parse(), Print(), QueryDoubleAttribute(), QueryIntAttribute(), QueryValueAttribute(), RemoveAttribute(), and SetAttribute().