#include <tinyxml.h>
Inheritance diagram for TiXmlElement:

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(). | |
| template<typename T> | |
| int | QueryValueAttribute (const std::string &name, T *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) |
| STL std::string form. | |
| void | SetAttribute (const std::string &name, int _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 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 () |
| virtual void | StreamIn (std::istream *in, TIXML_STRING *tag) |
| const char * | ReadValue (const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding) |
Private Attributes | |
| TiXmlAttributeSet | attributeSet |
Definition at line 941 of file tinyxml.h.
|
|
Construct an element.
Definition at line 490 of file tinyxml.cpp. Referenced by Clone(). 00491 : TiXmlNode( TiXmlNode::ELEMENT ) 00492 { 00493 firstChild = lastChild = 0; 00494 value = _value; 00495 }
|
|
|
std::string constructor.
Definition at line 499 of file tinyxml.cpp. 00500 : TiXmlNode( TiXmlNode::ELEMENT ) 00501 { 00502 firstChild = lastChild = 0; 00503 value = _value; 00504 }
|
|
|
Definition at line 508 of file tinyxml.cpp. References CopyTo(). 00509 : TiXmlNode( TiXmlNode::ELEMENT ) 00510 { 00511 firstChild = lastChild = 0; 00512 copy.CopyTo( this ); 00513 }
|
|
|
Definition at line 523 of file tinyxml.cpp. References ClearThis(). 00524 {
00525 ClearThis();
00526 }
|
|
|
Walk the XML tree visiting this node and all of its children. Implements TiXmlNode. Definition at line 832 of file tinyxml.cpp. References TiXmlNode::Accept(), attributeSet, TiXmlAttributeSet::First(), TiXmlNode::FirstChild(), TiXmlNode::NextSibling(), TiXmlVisitor::VisitEnter(), and TiXmlVisitor::VisitExit(). 00833 {
00834 if ( visitor->VisitEnter( *this, attributeSet.First() ) )
00835 {
00836 for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
00837 {
00838 if ( !node->Accept( visitor ) )
00839 break;
00840 }
00841 }
00842 return visitor->VisitExit( *this );
00843 }
|
|
||||||||||||
|
Definition at line 612 of file tinyxml.cpp. References Attribute(), and s(). 00613 {
00614 const std::string* s = Attribute( name );
00615 if ( d )
00616 {
00617 if ( s ) {
00618 *d = atof( s->c_str() );
00619 }
00620 else {
00621 *d = 0;
00622 }
00623 }
00624 return s;
00625 }
|
|
||||||||||||
|
Definition at line 578 of file tinyxml.cpp. References Attribute(), and s(). 00579 {
00580 const std::string* s = Attribute( name );
00581 if ( i )
00582 {
00583 if ( s ) {
00584 *i = atoi( s->c_str() );
00585 }
00586 else {
00587 *i = 0;
00588 }
00589 }
00590 return s;
00591 }
|
|
|
Definition at line 551 of file tinyxml.cpp. References attributeSet, TiXmlAttributeSet::Find(), and TiXmlAttribute::ValueStr(). 00552 {
00553 const TiXmlAttribute* node = attributeSet.Find( name );
00554 if ( node )
00555 return &node->ValueStr();
00556 return 0;
00557 }
|
|
||||||||||||
|
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 595 of file tinyxml.cpp. References Attribute(), and s(). 00596 {
00597 const char* s = Attribute( name );
00598 if ( d )
00599 {
00600 if ( s ) {
00601 *d = atof( s );
00602 }
00603 else {
00604 *d = 0;
00605 }
00606 }
00607 return s;
00608 }
|
|
||||||||||||
|
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 561 of file tinyxml.cpp. References Attribute(), and s(). 00562 {
00563 const char* s = Attribute( name );
00564 if ( i )
00565 {
00566 if ( s ) {
00567 *i = atoi( s );
00568 }
00569 else {
00570 *i = 0;
00571 }
00572 }
00573 return s;
00574 }
|
|
|
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. Definition at line 541 of file tinyxml.cpp. References attributeSet, TiXmlAttributeSet::Find(), and TiXmlAttribute::Value(). Referenced by Attribute(), Anp::HistMan::ReadAxis(), and Anp::HistMan::ReadHistogram(). 00542 {
00543 const TiXmlAttribute* node = attributeSet.Find( name );
00544 if ( node )
00545 return node->Value();
00546 return 0;
00547 }
|
|
|
Definition at line 529 of file tinyxml.cpp. References attributeSet, TiXmlNode::Clear(), TiXmlAttributeSet::First(), and TiXmlAttributeSet::Remove(). Referenced by operator=(), and ~TiXmlElement(). 00530 {
00531 Clear();
00532 while( attributeSet.First() )
00533 {
00534 TiXmlAttribute* node = attributeSet.First();
00535 attributeSet.Remove( node );
00536 delete node;
00537 }
00538 }
|
|
|
Creates a new Element and returns it - the returned element is a copy.
Implements TiXmlNode. Definition at line 846 of file tinyxml.cpp. References CopyTo(), TiXmlElement(), and TiXmlNode::Value(). 00847 {
00848 TiXmlElement* clone = new TiXmlElement( Value() );
00849 if ( !clone )
00850 return 0;
00851
00852 CopyTo( clone );
00853 return clone;
00854 }
|
|
|
Definition at line 810 of file tinyxml.cpp. References attributeSet, TiXmlNode::Clone(), TiXmlNode::CopyTo(), TiXmlAttributeSet::First(), TiXmlNode::LinkEndChild(), TiXmlAttribute::Name(), TiXmlAttribute::Next(), TiXmlNode::NextSibling(), SetAttribute(), and TiXmlAttribute::Value(). Referenced by Clone(), operator=(), and TiXmlElement(). 00811 {
00812 // superclass:
00813 TiXmlNode::CopyTo( target );
00814
00815 // Element class:
00816 // Clone the attributes, then clone the children.
00817 const TiXmlAttribute* attribute = 0;
00818 for( attribute = attributeSet.First();
00819 attribute;
00820 attribute = attribute->Next() )
00821 {
00822 target->SetAttribute( attribute->Name(), attribute->Value() );
00823 }
00824
00825 TiXmlNode* node = 0;
00826 for ( node = firstChild; node; node = node->NextSibling() )
00827 {
00828 target->LinkEndChild( node->Clone() );
00829 }
00830 }
|
|
|
Definition at line 1055 of file tinyxml.h. References attributeSet, and TiXmlAttributeSet::First(). 01055 { return attributeSet.First(); }
|
|
|
Access the first attribute in this element.
Definition at line 1054 of file tinyxml.h. References attributeSet, and TiXmlAttributeSet::First(). |
|
|
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 857 of file tinyxml.cpp. References TiXmlNode::FirstChild(), TiXmlNode::ToText(), and TiXmlNode::Value(). 00858 {
00859 const TiXmlNode* child = this->FirstChild();
00860 if ( child ) {
00861 const TiXmlText* childText = child->ToText();
00862 if ( childText ) {
00863 return childText->Value();
00864 }
00865 }
00866 return 0;
00867 }
|
|
|
Definition at line 1057 of file tinyxml.h. References attributeSet, and TiXmlAttributeSet::Last(). 01057 { return attributeSet.Last(); }
|
|
|
Access the last attribute in this element.
Definition at line 1056 of file tinyxml.h. References attributeSet, and TiXmlAttributeSet::Last(). |
|
|
Definition at line 516 of file tinyxml.cpp. References base, ClearThis(), and CopyTo().
|
|
||||||||||||||||
|
Implements TiXmlBase. Definition at line 1049 of file tinyxmlparser.cpp. References TiXmlAttributeSet::Add(), attributeSet, TiXmlParsingData::Cursor(), TiXmlAttributeSet::Find(), TiXmlNode::GetDocument(), TiXmlAttribute::Name(), TiXmlAttribute::NameTStr(), TiXmlAttribute::Parse(), TiXmlBase::ReadName(), ReadValue(), TiXmlAttribute::SetDocument(), TiXmlDocument::SetError(), TiXmlAttribute::SetValue(), TiXmlBase::SkipWhiteSpace(), TiXmlParsingData::Stamp(), TiXmlBase::StringEqual(), TIXML_STRING, and TiXmlAttribute::Value(). 01050 {
01051 p = SkipWhiteSpace( p, encoding );
01052 TiXmlDocument* document = GetDocument();
01053
01054 if ( !p || !*p )
01055 {
01056 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding );
01057 return 0;
01058 }
01059
01060 if ( data )
01061 {
01062 data->Stamp( p, encoding );
01063 location = data->Cursor();
01064 }
01065
01066 if ( *p != '<' )
01067 {
01068 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, p, data, encoding );
01069 return 0;
01070 }
01071
01072 p = SkipWhiteSpace( p+1, encoding );
01073
01074 // Read the name.
01075 const char* pErr = p;
01076
01077 p = ReadName( p, &value, encoding );
01078 if ( !p || !*p )
01079 {
01080 if ( document ) document->SetError( TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding );
01081 return 0;
01082 }
01083
01084 TIXML_STRING endTag ("</");
01085 endTag += value;
01086 endTag += ">";
01087
01088 // Check for and read attributes. Also look for an empty
01089 // tag or an end tag.
01090 while ( p && *p )
01091 {
01092 pErr = p;
01093 p = SkipWhiteSpace( p, encoding );
01094 if ( !p || !*p )
01095 {
01096 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
01097 return 0;
01098 }
01099 if ( *p == '/' )
01100 {
01101 ++p;
01102 // Empty tag.
01103 if ( *p != '>' )
01104 {
01105 if ( document ) document->SetError( TIXML_ERROR_PARSING_EMPTY, p, data, encoding );
01106 return 0;
01107 }
01108 return (p+1);
01109 }
01110 else if ( *p == '>' )
01111 {
01112 // Done with attributes (if there were any.)
01113 // Read the value -- which can include other
01114 // elements -- read the end tag, and return.
01115 ++p;
01116 p = ReadValue( p, data, encoding ); // Note this is an Element method, and will set the error if one happens.
01117 if ( !p || !*p )
01118 return 0;
01119
01120 // We should find the end tag now
01121 if ( StringEqual( p, endTag.c_str(), false, encoding ) )
01122 {
01123 p += endTag.length();
01124 return p;
01125 }
01126 else
01127 {
01128 if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
01129 return 0;
01130 }
01131 }
01132 else
01133 {
01134 // Try to read an attribute:
01135 TiXmlAttribute* attrib = new TiXmlAttribute();
01136 if ( !attrib )
01137 {
01138 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, pErr, data, encoding );
01139 return 0;
01140 }
01141
01142 attrib->SetDocument( document );
01143 pErr = p;
01144 p = attrib->Parse( p, data, encoding );
01145
01146 if ( !p || !*p )
01147 {
01148 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
01149 delete attrib;
01150 return 0;
01151 }
01152
01153 // Handle the strange case of double attributes:
01154 #ifdef TIXML_USE_STL
01155 TiXmlAttribute* node = attributeSet.Find( attrib->NameTStr() );
01156 #else
01157 TiXmlAttribute* node = attributeSet.Find( attrib->Name() );
01158 #endif
01159 if ( node )
01160 {
01161 node->SetValue( attrib->Value() );
01162 delete attrib;
01163 return 0;
01164 }
01165
01166 attributeSet.Add( attrib );
01167 }
01168 }
01169 return p;
01170 }
|
|
||||||||||||
|
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 757 of file tinyxml.cpp. References attributeSet, TiXmlAttributeSet::First(), TiXmlAttribute::Next(), TiXmlNode::NextSibling(), TiXmlBase::Print(), TiXmlAttribute::Print(), and TiXmlNode::ToText(). 00758 {
00759 int i;
00760 assert( cfile );
00761 for ( i=0; i<depth; i++ ) {
00762 fprintf( cfile, " " );
00763 }
00764
00765 fprintf( cfile, "<%s", value.c_str() );
00766
00767 const TiXmlAttribute* attrib;
00768 for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
00769 {
00770 fprintf( cfile, " " );
00771 attrib->Print( cfile, depth );
00772 }
00773
00774 // There are 3 different formatting approaches:
00775 // 1) An element without children is printed as a <foo /> node
00776 // 2) An element with only a text child is printed as <foo> text </foo>
00777 // 3) An element with children is printed on multiple lines.
00778 TiXmlNode* node;
00779 if ( !firstChild )
00780 {
00781 fprintf( cfile, " />" );
00782 }
00783 else if ( firstChild == lastChild && firstChild->ToText() )
00784 {
00785 fprintf( cfile, ">" );
00786 firstChild->Print( cfile, depth + 1 );
00787 fprintf( cfile, "</%s>", value.c_str() );
00788 }
00789 else
00790 {
00791 fprintf( cfile, ">" );
00792
00793 for ( node = firstChild; node; node=node->NextSibling() )
00794 {
00795 if ( !node->ToText() )
00796 {
00797 fprintf( cfile, "\n" );
00798 }
00799 node->Print( cfile, depth+1 );
00800 }
00801 fprintf( cfile, "\n" );
00802 for( i=0; i<depth; ++i ) {
00803 fprintf( cfile, " " );
00804 }
00805 fprintf( cfile, "</%s>", value.c_str() );
00806 }
00807 }
|
|
||||||||||||
|
Definition at line 659 of file tinyxml.cpp. References attributeSet, TiXmlAttributeSet::Find(), and TiXmlAttribute::QueryDoubleValue(). 00660 {
00661 const TiXmlAttribute* node = attributeSet.Find( name );
00662 if ( !node )
00663 return TIXML_NO_ATTRIBUTE;
00664 return node->QueryDoubleValue( dval );
00665 }
|
|
||||||||||||
|
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
Definition at line 649 of file tinyxml.cpp. References attributeSet, TiXmlAttributeSet::Find(), and TiXmlAttribute::QueryDoubleValue(). Referenced by QueryFloatAttribute(). 00650 {
00651 const TiXmlAttribute* node = attributeSet.Find( name );
00652 if ( !node )
00653 return TIXML_NO_ATTRIBUTE;
00654 return node->QueryDoubleValue( dval );
00655 }
|
|
||||||||||||
|
QueryFloatAttribute examines the attribute - see QueryIntAttribute().
Definition at line 990 of file tinyxml.h. References QueryDoubleAttribute(). Referenced by Anp::HistMan::ReadAxis(). 00990 {
00991 double d;
00992 int result = QueryDoubleAttribute( name, &d );
00993 if ( result == TIXML_SUCCESS ) {
00994 *_value = (float)d;
00995 }
00996 return result;
00997 }
|
|
||||||||||||
|
Definition at line 639 of file tinyxml.cpp. References attributeSet, TiXmlAttributeSet::Find(), and TiXmlAttribute::QueryIntValue(). 00640 {
00641 const TiXmlAttribute* node = attributeSet.Find( name );
00642 if ( !node )
00643 return TIXML_NO_ATTRIBUTE;
00644 return node->QueryIntValue( ival );
00645 }
|
|
||||||||||||
|
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 629 of file tinyxml.cpp. References attributeSet, TiXmlAttributeSet::Find(), and TiXmlAttribute::QueryIntValue(). Referenced by Anp::HistMan::ReadAxis(). 00630 {
00631 const TiXmlAttribute* node = attributeSet.Find( name );
00632 if ( !node )
00633 return TIXML_NO_ATTRIBUTE;
00634 return node->QueryIntValue( ival );
00635 }
|
|
||||||||||||||||
|
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.
Definition at line 1005 of file tinyxml.h. References attributeSet, TiXmlAttributeSet::Find(), and TiXmlAttribute::ValueStr(). 01006 {
01007 const TiXmlAttribute* node = attributeSet.Find( name );
01008 if ( !node )
01009 return TIXML_NO_ATTRIBUTE;
01010
01011 std::stringstream sstream( node->ValueStr() );
01012 sstream >> *outValue;
01013 if ( !sstream.fail() )
01014 return TIXML_SUCCESS;
01015 return TIXML_WRONG_TYPE;
01016 }
|
|
||||||||||||||||
|
Definition at line 1173 of file tinyxmlparser.cpp. References TiXmlText::Blank(), TiXmlNode::GetDocument(), TiXmlNode::Identify(), TiXmlBase::IsWhiteSpaceCondensed(), TiXmlNode::LinkEndChild(), TiXmlBase::Parse(), TiXmlText::Parse(), TiXmlDocument::SetError(), TiXmlBase::SkipWhiteSpace(), and TiXmlBase::StringEqual(). Referenced by Parse(). 01174 {
01175 TiXmlDocument* document = GetDocument();
01176
01177 // Read in text and elements in any order.
01178 const char* pWithWhiteSpace = p;
01179 p = SkipWhiteSpace( p, encoding );
01180
01181 while ( p && *p )
01182 {
01183 if ( *p != '<' )
01184 {
01185 // Take what we have, make a text element.
01186 TiXmlText* textNode = new TiXmlText( "" );
01187
01188 if ( !textNode )
01189 {
01190 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
01191 return 0;
01192 }
01193
01194 if ( TiXmlBase::IsWhiteSpaceCondensed() )
01195 {
01196 p = textNode->Parse( p, data, encoding );
01197 }
01198 else
01199 {
01200 // Special case: we want to keep the white space
01201 // so that leading spaces aren't removed.
01202 p = textNode->Parse( pWithWhiteSpace, data, encoding );
01203 }
01204
01205 if ( !textNode->Blank() )
01206 LinkEndChild( textNode );
01207 else
01208 delete textNode;
01209 }
01210 else
01211 {
01212 // We hit a '<'
01213 // Have we hit a new element or an end tag? This could also be
01214 // a TiXmlText in the "CDATA" style.
01215 if ( StringEqual( p, "</", false, encoding ) )
01216 {
01217 return p;
01218 }
01219 else
01220 {
01221 TiXmlNode* node = Identify( p, encoding );
01222 if ( node )
01223 {
01224 p = node->Parse( p, data, encoding );
01225 LinkEndChild( node );
01226 }
01227 else
01228 {
01229 return 0;
01230 }
01231 }
01232 }
01233 pWithWhiteSpace = p;
01234 p = SkipWhiteSpace( p, encoding );
01235 }
01236
01237 if ( !p )
01238 {
01239 if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding );
01240 }
01241 return p;
01242 }
|
|
|
STL std::string form.
Definition at line 1051 of file tinyxml.h. References RemoveAttribute(). |
|
|
Deletes an attribute with the given name. Definition at line 402 of file tinyxml.cpp. References attributeSet, TiXmlAttributeSet::Find(), TiXmlAttributeSet::Remove(), and TIXML_STRING. Referenced by RemoveAttribute(). 00403 {
00404 #ifdef TIXML_USE_STL
00405 TIXML_STRING str( name );
00406 TiXmlAttribute* node = attributeSet.Find( str );
00407 #else
00408 TiXmlAttribute* node = attributeSet.Find( name );
00409 #endif
00410 if ( node )
00411 {
00412 attributeSet.Remove( node );
00413 delete node;
00414 }
00415 }
|
|
||||||||||||
|
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 669 of file tinyxml.cpp. References SetAttribute(). 00670 {
00671 char buf[64];
00672 #if defined(TIXML_SNPRINTF)
00673 TIXML_SNPRINTF( buf, sizeof(buf), "%d", val );
00674 #else
00675 sprintf( buf, "%d", val );
00676 #endif
00677 SetAttribute( name, buf );
00678 }
|
|
||||||||||||
|
Definition at line 682 of file tinyxml.cpp. References SetAttribute(). 00683 {
00684 std::ostringstream oss;
00685 oss << val;
00686 SetAttribute( name, oss.str() );
00687 }
|
|
||||||||||||
|
STL std::string form.
Definition at line 734 of file tinyxml.cpp. References TiXmlAttributeSet::Add(), attributeSet, TiXmlAttributeSet::Find(), TiXmlNode::GetDocument(), TiXmlDocument::SetError(), TiXmlAttribute::SetValue(), and TIXML_ENCODING_UNKNOWN. 00735 {
00736 TiXmlAttribute* node = attributeSet.Find( name );
00737 if ( node )
00738 {
00739 node->SetValue( _value );
00740 return;
00741 }
00742
00743 TiXmlAttribute* attrib = new TiXmlAttribute( name, _value );
00744 if ( attrib )
00745 {
00746 attributeSet.Add( attrib );
00747 }
00748 else
00749 {
00750 TiXmlDocument* document = GetDocument();
00751 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN );
00752 }
00753 }
|
|
||||||||||||
|
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 703 of file tinyxml.cpp. References TiXmlAttributeSet::Add(), attributeSet, TiXmlAttributeSet::Find(), TiXmlNode::GetDocument(), TiXmlDocument::SetError(), TiXmlAttribute::SetValue(), TIXML_ENCODING_UNKNOWN, and TIXML_STRING. Referenced by CopyTo(), SetAttribute(), and SetDoubleAttribute(). 00704 {
00705 #ifdef TIXML_USE_STL
00706 TIXML_STRING _name( cname );
00707 TIXML_STRING _value( cvalue );
00708 #else
00709 const char* _name = cname;
00710 const char* _value = cvalue;
00711 #endif
00712
00713 TiXmlAttribute* node = attributeSet.Find( _name );
00714 if ( node )
00715 {
00716 node->SetValue( _value );
00717 return;
00718 }
00719
00720 TiXmlAttribute* attrib = new TiXmlAttribute( cname, cvalue );
00721 if ( attrib )
00722 {
00723 attributeSet.Add( attrib );
00724 }
00725 else
00726 {
00727 TiXmlDocument* document = GetDocument();
00728 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN );
00729 }
00730 }
|
|
||||||||||||
|
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 691 of file tinyxml.cpp. References SetAttribute(). 00692 {
00693 char buf[256];
00694 #if defined(TIXML_SNPRINTF)
00695 TIXML_SNPRINTF( buf, sizeof(buf), "%f", val );
00696 #else
00697 sprintf( buf, "%f", val );
00698 #endif
00699 SetAttribute( name, buf );
00700 }
|
|
||||||||||||
|
Implements TiXmlNode. Definition at line 909 of file tinyxmlparser.cpp. References TiXmlNode::GetDocument(), TiXmlNode::Identify(), TiXmlBase::IsWhiteSpace(), len, TiXmlDocument::SetError(), TiXmlNode::StreamIn(), TiXmlText::StreamIn(), TiXmlBase::StreamWhiteSpace(), TIXML_DEFAULT_ENCODING, and TIXML_ENCODING_UNKNOWN. 00910 {
00911 // We're called with some amount of pre-parsing. That is, some of "this"
00912 // element is in "tag". Go ahead and stream to the closing ">"
00913 while( in->good() )
00914 {
00915 int c = in->get();
00916 if ( c <= 0 )
00917 {
00918 TiXmlDocument* document = GetDocument();
00919 if ( document )
00920 document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
00921 return;
00922 }
00923 (*tag) += (char) c ;
00924
00925 if ( c == '>' )
00926 break;
00927 }
00928
00929 if ( tag->length() < 3 ) return;
00930
00931 // Okay...if we are a "/>" tag, then we're done. We've read a complete tag.
00932 // If not, identify and stream.
00933
00934 if ( tag->at( tag->length() - 1 ) == '>'
00935 && tag->at( tag->length() - 2 ) == '/' )
00936 {
00937 // All good!
00938 return;
00939 }
00940 else if ( tag->at( tag->length() - 1 ) == '>' )
00941 {
00942 // There is more. Could be:
00943 // text
00944 // cdata text (which looks like another node)
00945 // closing tag
00946 // another node.
00947 for ( ;; )
00948 {
00949 StreamWhiteSpace( in, tag );
00950
00951 // Do we have text?
00952 if ( in->good() && in->peek() != '<' )
00953 {
00954 // Yep, text.
00955 TiXmlText text( "" );
00956 text.StreamIn( in, tag );
00957
00958 // What follows text is a closing tag or another node.
00959 // Go around again and figure it out.
00960 continue;
00961 }
00962
00963 // We now have either a closing tag...or another node.
00964 // We should be at a "<", regardless.
00965 if ( !in->good() ) return;
00966 assert( in->peek() == '<' );
00967 int tagIndex = (int) tag->length();
00968
00969 bool closingTag = false;
00970 bool firstCharFound = false;
00971
00972 for( ;; )
00973 {
00974 if ( !in->good() )
00975 return;
00976
00977 int c = in->peek();
00978 if ( c <= 0 )
00979 {
00980 TiXmlDocument* document = GetDocument();
00981 if ( document )
00982 document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
00983 return;
00984 }
00985
00986 if ( c == '>' )
00987 break;
00988
00989 *tag += (char) c;
00990 in->get();
00991
00992 // Early out if we find the CDATA id.
00993 if ( c == '[' && tag->size() >= 9 )
00994 {
00995 size_t len = tag->size();
00996 const char* start = tag->c_str() + len - 9;
00997 if ( strcmp( start, "<![CDATA[" ) == 0 ) {
00998 assert( !closingTag );
00999 break;
01000 }
01001 }
01002
01003 if ( !firstCharFound && c != '<' && !IsWhiteSpace( c ) )
01004 {
01005 firstCharFound = true;
01006 if ( c == '/' )
01007 closingTag = true;
01008 }
01009 }
01010 // If it was a closing tag, then read in the closing '>' to clean up the input stream.
01011 // If it was not, the streaming will be done by the tag.
01012 if ( closingTag )
01013 {
01014 if ( !in->good() )
01015 return;
01016
01017 int c = in->get();
01018 if ( c <= 0 )
01019 {
01020 TiXmlDocument* document = GetDocument();
01021 if ( document )
01022 document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
01023 return;
01024 }
01025 assert( c == '>' );
01026 *tag += (char) c;
01027
01028 // We are done, once we've found our closing tag.
01029 return;
01030 }
01031 else
01032 {
01033 // If not a closing tag, id it, and stream.
01034 const char* tagloc = tag->c_str() + tagIndex;
01035 TiXmlNode* node = Identify( tagloc, TIXML_DEFAULT_ENCODING );
01036 if ( !node )
01037 return;
01038 node->StreamIn( in, tag );
01039 delete node;
01040 node = 0;
01041
01042 // No return: go around from the beginning: text, closing tag, or node.
01043 }
01044 }
01045 }
01046 }
|
|
|
Cast to a more defined type. Will return null not of the requested type.
Reimplemented from TiXmlNode. |
|
|
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. Referenced by Accept(), Attribute(), ClearThis(), CopyTo(), FirstAttribute(), LastAttribute(), Parse(), Print(), QueryDoubleAttribute(), QueryIntAttribute(), QueryValueAttribute(), RemoveAttribute(), and SetAttribute(). |
1.3.9.1