TiXmlNode Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlNode:
TiXmlBase TiXmlComment TiXmlDeclaration TiXmlDocument TiXmlElement TiXmlText TiXmlUnknown

List of all members.

Public Types

enum  NodeType {
  DOCUMENT, ELEMENT, COMMENT, UNKNOWN,
  TEXT, DECLARATION, TYPECOUNT
}

Public Member Functions

virtual ~TiXmlNode ()
const char * Value () const
const std::string & ValueStr () const
void SetValue (const char *_value)
void SetValue (const std::string &_value)
 STL std::string form.
void Clear ()
 Delete all the children of this node. Does not affect 'this'.
TiXmlNodeParent ()
 One step up the DOM.
const TiXmlNodeParent () const
const TiXmlNodeFirstChild () const
 The first child of this node. Will be null if there are no children.
TiXmlNodeFirstChild ()
const TiXmlNodeFirstChild (const char *value) const
TiXmlNodeFirstChild (const char *_value)
 The first child of this node with the matching 'value'. Will be null if none found.
const TiXmlNodeLastChild () const
TiXmlNodeLastChild ()
 The last child of this node. Will be null if there are no children.
const TiXmlNodeLastChild (const char *value) const
TiXmlNodeLastChild (const char *_value)
 The last child of this node matching 'value'. Will be null if there are no children.
const TiXmlNodeFirstChild (const std::string &_value) const
 STL std::string form.
TiXmlNodeFirstChild (const std::string &_value)
 STL std::string form.
const TiXmlNodeLastChild (const std::string &_value) const
 STL std::string form.
TiXmlNodeLastChild (const std::string &_value)
 STL std::string form.
const TiXmlNodeIterateChildren (const TiXmlNode *previous) const
TiXmlNodeIterateChildren (const TiXmlNode *previous)
const TiXmlNodeIterateChildren (const char *value, const TiXmlNode *previous) const
 This flavor of IterateChildren searches for children with a particular 'value'.
TiXmlNodeIterateChildren (const char *_value, const TiXmlNode *previous)
const TiXmlNodeIterateChildren (const std::string &_value, const TiXmlNode *previous) const
 STL std::string form.
TiXmlNodeIterateChildren (const std::string &_value, const TiXmlNode *previous)
 STL std::string form.
TiXmlNodeInsertEndChild (const TiXmlNode &addThis)
TiXmlNodeLinkEndChild (TiXmlNode *addThis)
TiXmlNodeInsertBeforeChild (TiXmlNode *beforeThis, const TiXmlNode &addThis)
TiXmlNodeInsertAfterChild (TiXmlNode *afterThis, const TiXmlNode &addThis)
TiXmlNodeReplaceChild (TiXmlNode *replaceThis, const TiXmlNode &withThis)
bool RemoveChild (TiXmlNode *removeThis)
 Delete a child of this node.
const TiXmlNodePreviousSibling () const
 Navigate to a sibling node.
TiXmlNodePreviousSibling ()
const TiXmlNodePreviousSibling (const char *) const
 Navigate to a sibling node.
TiXmlNodePreviousSibling (const char *_prev)
const TiXmlNodePreviousSibling (const std::string &_value) const
 STL std::string form.
TiXmlNodePreviousSibling (const std::string &_value)
 STL std::string form.
const TiXmlNodeNextSibling (const std::string &_value) const
 STL std::string form.
TiXmlNodeNextSibling (const std::string &_value)
 STL std::string form.
const TiXmlNodeNextSibling () const
 Navigate to a sibling node.
TiXmlNodeNextSibling ()
const TiXmlNodeNextSibling (const char *) const
 Navigate to a sibling node with the given 'value'.
TiXmlNodeNextSibling (const char *_next)
const TiXmlElementNextSiblingElement () const
TiXmlElementNextSiblingElement ()
const TiXmlElementNextSiblingElement (const char *) const
TiXmlElementNextSiblingElement (const char *_next)
const TiXmlElementNextSiblingElement (const std::string &_value) const
 STL std::string form.
TiXmlElementNextSiblingElement (const std::string &_value)
 STL std::string form.
const TiXmlElementFirstChildElement () const
 Convenience function to get through elements.
TiXmlElementFirstChildElement ()
const TiXmlElementFirstChildElement (const char *_value) const
 Convenience function to get through elements.
TiXmlElementFirstChildElement (const char *_value)
const TiXmlElementFirstChildElement (const std::string &_value) const
 STL std::string form.
TiXmlElementFirstChildElement (const std::string &_value)
 STL std::string form.
int Type () const
const TiXmlDocumentGetDocument () const
TiXmlDocumentGetDocument ()
bool NoChildren () const
 Returns true if this node has no children.
virtual const TiXmlDocumentToDocument () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlElementToElement () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlCommentToComment () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlUnknownToUnknown () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlTextToText () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlDeclarationToDeclaration () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlDocumentToDocument ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlElementToElement ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlCommentToComment ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlUnknownToUnknown ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlTextToText ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlDeclarationToDeclaration ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlNodeClone () const =0
virtual bool Accept (TiXmlVisitor *visitor) const =0

Protected Member Functions

 TiXmlNode (NodeType _type)
void CopyTo (TiXmlNode *target) const
virtual void StreamIn (std::istream *in, TIXML_STRING *tag)=0
TiXmlNodeIdentify (const char *start, TiXmlEncoding encoding)

Protected Attributes

TiXmlNodeparent
NodeType type
TiXmlNodefirstChild
TiXmlNodelastChild
TIXML_STRING value
TiXmlNodeprev
TiXmlNodenext

Private Member Functions

 TiXmlNode (const TiXmlNode &)
void operator= (const TiXmlNode &base)

Friends

class TiXmlDocument
class TiXmlElement
std::istream & operator>> (std::istream &in, TiXmlNode &base)
std::ostream & operator<< (std::ostream &out, const TiXmlNode &base)
std::string & operator<< (std::string &out, const TiXmlNode &base)
 Appends the XML node or attribute to a std::string.

Detailed Description

The parent class for everything in the Document Object Model. (Except for attributes). Nodes have siblings, a parent, and children. A node can be in a document, or stand on its own. The type of a TiXmlNode can be queried, and it can be cast to its more defined type.

Definition at line 423 of file tinyxml.h.


Member Enumeration Documentation

The types of XML nodes supported by TinyXml. (All the unsupported types are picked up by UNKNOWN.)

Enumerator:
DOCUMENT 
ELEMENT 
COMMENT 
UNKNOWN 
TEXT 
DECLARATION 
TYPECOUNT 

Definition at line 462 of file tinyxml.h.

00463         {
00464                 DOCUMENT,
00465                 ELEMENT,
00466                 COMMENT,
00467                 UNKNOWN,
00468                 TEXT,
00469                 DECLARATION,
00470                 TYPECOUNT
00471         };


Constructor & Destructor Documentation

TiXmlNode::~TiXmlNode (  )  [virtual]

Definition at line 132 of file tinyxml.cpp.

References firstChild, and next.

00133 {
00134         TiXmlNode* node = firstChild;
00135         TiXmlNode* temp = 0;
00136 
00137         while ( node )
00138         {
00139                 temp = node;
00140                 node = node->next;
00141                 delete temp;
00142         }       
00143 }

TiXmlNode::TiXmlNode ( NodeType  _type  )  [protected]

Definition at line 121 of file tinyxml.cpp.

References firstChild, lastChild, next, parent, prev, and type.

00121                                      : TiXmlBase()
00122 {
00123         parent = 0;
00124         type = _type;
00125         firstChild = 0;
00126         lastChild = 0;
00127         prev = 0;
00128         next = 0;
00129 }

TiXmlNode::TiXmlNode ( const TiXmlNode  )  [private]

Member Function Documentation

virtual bool TiXmlNode::Accept ( TiXmlVisitor visitor  )  const [pure virtual]

Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the XML tree will be conditionally visited and the host will be called back via the TiXmlVisitor interface.

This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse the XML for the callbacks, so the performance of TinyXML is unchanged by using this interface versus any other.)

The interface has been based on ideas from:

Which are both good references for "visiting".

An example of using Accept():

		TiXmlPrinter printer;
		tinyxmlDoc.Accept( &printer );
		const char* xmlcstr = printer.CStr();
		

Implemented in TiXmlElement, TiXmlComment, TiXmlText, TiXmlDeclaration, TiXmlUnknown, and TiXmlDocument.

void TiXmlNode::Clear ( void   ) 

Delete all the children of this node. Does not affect 'this'.

Definition at line 153 of file tinyxml.cpp.

References firstChild, lastChild, and next.

Referenced by TiXmlElement::ClearThis(), TiXmlDocument::LoadFile(), TiXmlComment::operator=(), TiXmlDocument::operator=(), and TiXmlDeclaration::operator=().

00154 {
00155         TiXmlNode* node = firstChild;
00156         TiXmlNode* temp = 0;
00157 
00158         while ( node )
00159         {
00160                 temp = node;
00161                 node = node->next;
00162                 delete temp;
00163         }       
00164 
00165         firstChild = 0;
00166         lastChild = 0;
00167 }

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

Create an exact duplicate of this node and return it. The memory must be deleted by the caller.

Implemented in TiXmlElement, TiXmlComment, TiXmlText, TiXmlDeclaration, TiXmlUnknown, and TiXmlDocument.

Referenced by TiXmlElement::CopyTo(), TiXmlDocument::CopyTo(), InsertAfterChild(), InsertBeforeChild(), InsertEndChild(), and ReplaceChild().

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

Reimplemented in TiXmlElement, TiXmlComment, TiXmlText, TiXmlDeclaration, TiXmlUnknown, and TiXmlDocument.

Definition at line 146 of file tinyxml.cpp.

References SetValue(), TiXmlBase::userData, and value.

00147 {
00148         target->SetValue (value.c_str() );
00149         target->userData = userData; 
00150 }

TiXmlNode* TiXmlNode::FirstChild ( const std::string &  _value  )  [inline]

STL std::string form.

Definition at line 539 of file tinyxml.h.

References FirstChild().

Referenced by FirstChild().

const TiXmlNode* TiXmlNode::FirstChild ( const std::string &  _value  )  const [inline]

STL std::string form.

Definition at line 538 of file tinyxml.h.

References FirstChild().

Referenced by FirstChild().

TiXmlNode* TiXmlNode::FirstChild ( const char *  _value  )  [inline]

The first child of this node with the matching 'value'. Will be null if none found.

Definition at line 524 of file tinyxml.h.

00524                                                      {
00525                 // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe)
00526                 // call the method, cast the return back to non-const.
00527                 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00528         }

const TiXmlNode * TiXmlNode::FirstChild ( const char *  value  )  const

The first child of this node with the matching 'value'. Will be null if none found.

Definition at line 326 of file tinyxml.cpp.

References firstChild, next, and Value().

00327 {
00328         const TiXmlNode* node;
00329         for ( node = firstChild; node; node = node->next )
00330         {
00331                 if ( strcmp( node->Value(), _value ) == 0 )
00332                         return node;
00333         }
00334         return 0;
00335 }

TiXmlNode* TiXmlNode::FirstChild (  )  [inline]

Definition at line 521 of file tinyxml.h.

References firstChild.

00521 { return firstChild; }

const TiXmlNode* TiXmlNode::FirstChild (  )  const [inline]
TiXmlElement* TiXmlNode::FirstChildElement ( const std::string &  _value  )  [inline]

STL std::string form.

Definition at line 675 of file tinyxml.h.

References FirstChildElement().

Referenced by FirstChildElement().

const TiXmlElement* TiXmlNode::FirstChildElement ( const std::string &  _value  )  const [inline]

STL std::string form.

Definition at line 674 of file tinyxml.h.

References FirstChildElement().

Referenced by FirstChildElement().

TiXmlElement* TiXmlNode::FirstChildElement ( const char *  _value  )  [inline]

Definition at line 669 of file tinyxml.h.

00669                                                                {
00670                 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00671         }

const TiXmlElement * TiXmlNode::FirstChildElement ( const char *  _value  )  const

Convenience function to get through elements.

Definition at line 432 of file tinyxml.cpp.

References FirstChild(), NextSibling(), and ToElement().

00433 {
00434         const TiXmlNode* node;
00435 
00436         for (   node = FirstChild( _value );
00437                         node;
00438                         node = node->NextSibling( _value ) )
00439         {
00440                 if ( node->ToElement() )
00441                         return node->ToElement();
00442         }
00443         return 0;
00444 }

TiXmlElement* TiXmlNode::FirstChildElement (  )  [inline]

Definition at line 663 of file tinyxml.h.

00663                                           {
00664                 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00665         }

const TiXmlElement * TiXmlNode::FirstChildElement (  )  const

Convenience function to get through elements.

Definition at line 417 of file tinyxml.cpp.

References FirstChild(), NextSibling(), and ToElement().

Referenced by TiXmlDocument::RootElement().

00418 {
00419         const TiXmlNode* node;
00420 
00421         for (   node = FirstChild();
00422                         node;
00423                         node = node->NextSibling() )
00424         {
00425                 if ( node->ToElement() )
00426                         return node->ToElement();
00427         }
00428         return 0;
00429 }

TiXmlDocument* TiXmlNode::GetDocument (  )  [inline]

Definition at line 688 of file tinyxml.h.

00688                                      {
00689                 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00690         }

const TiXmlDocument * TiXmlNode::GetDocument (  )  const

Return a pointer to the Document this node lives in. Returns null if not in a document.

Definition at line 477 of file tinyxml.cpp.

References parent, and ToDocument().

Referenced by Identify(), InsertAfterChild(), InsertBeforeChild(), InsertEndChild(), LinkEndChild(), TiXmlComment::Parse(), TiXmlElement::Parse(), TiXmlDeclaration::Parse(), TiXmlUnknown::Parse(), TiXmlText::Parse(), TiXmlElement::ReadValue(), TiXmlElement::SetAttribute(), TiXmlDeclaration::StreamIn(), TiXmlComment::StreamIn(), TiXmlElement::StreamIn(), TiXmlText::StreamIn(), and TiXmlUnknown::StreamIn().

00478 {
00479         const TiXmlNode* node;
00480 
00481         for( node = this; node; node = node->parent )
00482         {
00483                 if ( node->ToDocument() )
00484                         return node->ToDocument();
00485         }
00486         return 0;
00487 }

TiXmlNode * TiXmlNode::Identify ( const char *  start,
TiXmlEncoding  encoding 
) [protected]

Definition at line 818 of file tinyxmlparser.cpp.

References doc, GetDocument(), TiXmlBase::IsAlpha(), parent, TiXmlText::SetCDATA(), TiXmlDocument::SetError(), TiXmlBase::SkipWhiteSpace(), TiXmlBase::StringEqual(), TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR_OUT_OF_MEMORY, and TiXmlElement.

Referenced by TiXmlDocument::Parse(), TiXmlElement::ReadValue(), TiXmlDocument::StreamIn(), and TiXmlElement::StreamIn().

00819 {
00820         TiXmlNode* returnNode = 0;
00821 
00822         p = SkipWhiteSpace( p, encoding );
00823         if( !p || !*p || *p != '<' )
00824         {
00825                 return 0;
00826         }
00827 
00828         TiXmlDocument* doc = GetDocument();
00829         p = SkipWhiteSpace( p, encoding );
00830 
00831         if ( !p || !*p )
00832         {
00833                 return 0;
00834         }
00835 
00836         // What is this thing? 
00837         // - Elements start with a letter or underscore, but xml is reserved.
00838         // - Comments: <!--
00839         // - Decleration: <?xml
00840         // - Everthing else is unknown to tinyxml.
00841         //
00842 
00843         const char* xmlHeader = { "<?xml" };
00844         const char* commentHeader = { "<!--" };
00845         const char* dtdHeader = { "<!" };
00846         const char* cdataHeader = { "<![CDATA[" };
00847 
00848         if ( StringEqual( p, xmlHeader, true, encoding ) )
00849         {
00850                 #ifdef DEBUG_PARSER
00851                         TIXML_LOG( "XML parsing Declaration\n" );
00852                 #endif
00853                 returnNode = new TiXmlDeclaration();
00854         }
00855         else if ( StringEqual( p, commentHeader, false, encoding ) )
00856         {
00857                 #ifdef DEBUG_PARSER
00858                         TIXML_LOG( "XML parsing Comment\n" );
00859                 #endif
00860                 returnNode = new TiXmlComment();
00861         }
00862         else if ( StringEqual( p, cdataHeader, false, encoding ) )
00863         {
00864                 #ifdef DEBUG_PARSER
00865                         TIXML_LOG( "XML parsing CDATA\n" );
00866                 #endif
00867                 TiXmlText* text = new TiXmlText( "" );
00868                 text->SetCDATA( true );
00869                 returnNode = text;
00870         }
00871         else if ( StringEqual( p, dtdHeader, false, encoding ) )
00872         {
00873                 #ifdef DEBUG_PARSER
00874                         TIXML_LOG( "XML parsing Unknown(1)\n" );
00875                 #endif
00876                 returnNode = new TiXmlUnknown();
00877         }
00878         else if (    IsAlpha( *(p+1), encoding )
00879                           || *(p+1) == '_' )
00880         {
00881                 #ifdef DEBUG_PARSER
00882                         TIXML_LOG( "XML parsing Element\n" );
00883                 #endif
00884                 returnNode = new TiXmlElement( "" );
00885         }
00886         else
00887         {
00888                 #ifdef DEBUG_PARSER
00889                         TIXML_LOG( "XML parsing Unknown(2)\n" );
00890                 #endif
00891                 returnNode = new TiXmlUnknown();
00892         }
00893 
00894         if ( returnNode )
00895         {
00896                 // Set the parent, so it can report errors
00897                 returnNode->parent = this;
00898         }
00899         else
00900         {
00901                 if ( doc )
00902                         doc->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN );
00903         }
00904         return returnNode;
00905 }

TiXmlNode * TiXmlNode::InsertAfterChild ( TiXmlNode afterThis,
const TiXmlNode addThis 
)

Add a new node related to this. Adds a child after the specified child. Returns a pointer to the new object or NULL if an error occured.

Definition at line 244 of file tinyxml.cpp.

References Clone(), DOCUMENT, GetDocument(), lastChild, next, parent, prev, TiXmlDocument::SetError(), TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY, and Type().

00245 {
00246         if ( !afterThis || afterThis->parent != this ) {
00247                 return 0;
00248         }
00249         if ( addThis.Type() == TiXmlNode::DOCUMENT )
00250         {
00251                 if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
00252                 return 0;
00253         }
00254 
00255         TiXmlNode* node = addThis.Clone();
00256         if ( !node )
00257                 return 0;
00258         node->parent = this;
00259 
00260         node->prev = afterThis;
00261         node->next = afterThis->next;
00262         if ( afterThis->next )
00263         {
00264                 afterThis->next->prev = node;
00265         }
00266         else
00267         {
00268                 assert( lastChild == afterThis );
00269                 lastChild = node;
00270         }
00271         afterThis->next = node;
00272         return node;
00273 }

TiXmlNode * TiXmlNode::InsertBeforeChild ( TiXmlNode beforeThis,
const TiXmlNode addThis 
)

Add a new node related to this. Adds a child before the specified child. Returns a pointer to the new object or NULL if an error occured.

Definition at line 212 of file tinyxml.cpp.

References Clone(), DOCUMENT, firstChild, GetDocument(), next, parent, prev, TiXmlDocument::SetError(), TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY, and Type().

00213 {       
00214         if ( !beforeThis || beforeThis->parent != this ) {
00215                 return 0;
00216         }
00217         if ( addThis.Type() == TiXmlNode::DOCUMENT )
00218         {
00219                 if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
00220                 return 0;
00221         }
00222 
00223         TiXmlNode* node = addThis.Clone();
00224         if ( !node )
00225                 return 0;
00226         node->parent = this;
00227 
00228         node->next = beforeThis;
00229         node->prev = beforeThis->prev;
00230         if ( beforeThis->prev )
00231         {
00232                 beforeThis->prev->next = node;
00233         }
00234         else
00235         {
00236                 assert( firstChild == beforeThis );
00237                 firstChild = node;
00238         }
00239         beforeThis->prev = node;
00240         return node;
00241 }

TiXmlNode * TiXmlNode::InsertEndChild ( const TiXmlNode addThis  ) 

Add a new node related to this. Adds a child past the LastChild. Returns a pointer to the new object or NULL if an error occured.

Definition at line 197 of file tinyxml.cpp.

References Clone(), DOCUMENT, GetDocument(), LinkEndChild(), TiXmlDocument::SetError(), TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY, and Type().

00198 {
00199         if ( addThis.Type() == TiXmlNode::DOCUMENT )
00200         {
00201                 if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
00202                 return 0;
00203         }
00204         TiXmlNode* node = addThis.Clone();
00205         if ( !node )
00206                 return 0;
00207 
00208         return LinkEndChild( node );
00209 }

TiXmlNode* TiXmlNode::IterateChildren ( const std::string &  _value,
const TiXmlNode previous 
) [inline]

STL std::string form.

Definition at line 573 of file tinyxml.h.

References IterateChildren().

Referenced by IterateChildren().

const TiXmlNode* TiXmlNode::IterateChildren ( const std::string &  _value,
const TiXmlNode previous 
) const [inline]

STL std::string form.

Definition at line 572 of file tinyxml.h.

References IterateChildren().

Referenced by IterateChildren().

TiXmlNode* TiXmlNode::IterateChildren ( const char *  _value,
const TiXmlNode previous 
) [inline]

Definition at line 567 of file tinyxml.h.

00567                                                                                      {
00568                 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00569         }

const TiXmlNode * TiXmlNode::IterateChildren ( const char *  value,
const TiXmlNode previous 
) const

This flavor of IterateChildren searches for children with a particular 'value'.

Definition at line 364 of file tinyxml.cpp.

References FirstChild(), NextSibling(), and parent.

00365 {
00366         if ( !previous )
00367         {
00368                 return FirstChild( val );
00369         }
00370         else
00371         {
00372                 assert( previous->parent == this );
00373                 return previous->NextSibling( val );
00374         }
00375 }

TiXmlNode* TiXmlNode::IterateChildren ( const TiXmlNode previous  )  [inline]

Definition at line 561 of file tinyxml.h.

00561                                                                 {
00562                 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00563         }

const TiXmlNode * TiXmlNode::IterateChildren ( const TiXmlNode previous  )  const

An alternate way to walk the children of a node. One way to iterate over nodes is:

			for( child = parent->FirstChild(); child; child = child->NextSibling() )
		

IterateChildren does the same thing with the syntax:

			child = 0;
			while( child = parent->IterateChildren( child ) )
		

IterateChildren takes the previous child as input and finds the next one. If the previous child is null, it returns the first. IterateChildren will return null when done.

Definition at line 350 of file tinyxml.cpp.

References FirstChild(), NextSibling(), and parent.

00351 {
00352         if ( !previous )
00353         {
00354                 return FirstChild();
00355         }
00356         else
00357         {
00358                 assert( previous->parent == this );
00359                 return previous->NextSibling();
00360         }
00361 }

TiXmlNode* TiXmlNode::LastChild ( const std::string &  _value  )  [inline]

STL std::string form.

Definition at line 541 of file tinyxml.h.

References LastChild().

Referenced by LastChild().

const TiXmlNode* TiXmlNode::LastChild ( const std::string &  _value  )  const [inline]

STL std::string form.

Definition at line 540 of file tinyxml.h.

References LastChild().

Referenced by LastChild().

TiXmlNode* TiXmlNode::LastChild ( const char *  _value  )  [inline]

The last child of this node matching 'value'. Will be null if there are no children.

Definition at line 533 of file tinyxml.h.

00533                                                     {
00534                 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00535         }

const TiXmlNode * TiXmlNode::LastChild ( const char *  value  )  const

Definition at line 338 of file tinyxml.cpp.

References lastChild, prev, and Value().

00339 {
00340         const TiXmlNode* node;
00341         for ( node = lastChild; node; node = node->prev )
00342         {
00343                 if ( strcmp( node->Value(), _value ) == 0 )
00344                         return node;
00345         }
00346         return 0;
00347 }

TiXmlNode* TiXmlNode::LastChild (  )  [inline]

The last child of this node. Will be null if there are no children.

Definition at line 530 of file tinyxml.h.

References lastChild.

00530 { return lastChild; }

const TiXmlNode* TiXmlNode::LastChild (  )  const [inline]

Definition at line 529 of file tinyxml.h.

References lastChild.

Referenced by TiXmlPrinter::VisitEnter().

00529 { return lastChild; }           

TiXmlNode * TiXmlNode::LinkEndChild ( TiXmlNode addThis  ) 

Add a new node related to this. Adds a child past the LastChild.

NOTE: the node to be added is passed by pointer, and will be henceforth owned (and deleted) by tinyXml. This method is efficient and avoids an extra copy, but should be used with care as it uses a different memory model than the other insert functions.

See also:
InsertEndChild

Definition at line 170 of file tinyxml.cpp.

References DOCUMENT, firstChild, GetDocument(), lastChild, next, parent, prev, TiXmlDocument::SetError(), TIXML_ENCODING_UNKNOWN, TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY, and Type().

Referenced by TiXmlElement::CopyTo(), TiXmlDocument::CopyTo(), InsertEndChild(), TiXmlDocument::Parse(), and TiXmlElement::ReadValue().

00171 {
00172         assert( node->parent == 0 || node->parent == this );
00173         assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() );
00174 
00175         if ( node->Type() == TiXmlNode::DOCUMENT )
00176         {
00177                 delete node;
00178                 if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
00179                 return 0;
00180         }
00181 
00182         node->parent = this;
00183 
00184         node->prev = lastChild;
00185         node->next = 0;
00186 
00187         if ( lastChild )
00188                 lastChild->next = node;
00189         else
00190                 firstChild = node;                      // it was an empty list.
00191 
00192         lastChild = node;
00193         return node;
00194 }

TiXmlNode* TiXmlNode::NextSibling ( const char *  _next  )  [inline]

Definition at line 634 of file tinyxml.h.

00634                                                     {
00635                 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00636         }

const TiXmlNode * TiXmlNode::NextSibling ( const char *  _value  )  const

Navigate to a sibling node with the given 'value'.

Definition at line 378 of file tinyxml.cpp.

References next, and Value().

00379 {
00380         const TiXmlNode* node;
00381         for ( node = next; node; node = node->next )
00382         {
00383                 if ( strcmp( node->Value(), _value ) == 0 )
00384                         return node;
00385         }
00386         return 0;
00387 }

TiXmlNode* TiXmlNode::NextSibling (  )  [inline]

Definition at line 630 of file tinyxml.h.

References next.

00630 { return next; }

const TiXmlNode* TiXmlNode::NextSibling (  )  const [inline]

Navigate to a sibling node.

Definition at line 629 of file tinyxml.h.

References next.

Referenced by NextSiblingElement().

00629 { return next; }

TiXmlNode* TiXmlNode::NextSibling ( const std::string &  _value  )  [inline]

STL std::string form.

Definition at line 625 of file tinyxml.h.

References NextSibling().

Referenced by NextSibling().

const TiXmlNode* TiXmlNode::NextSibling ( const std::string &  _value  )  const [inline]
TiXmlElement* TiXmlNode::NextSiblingElement ( const std::string &  _value  )  [inline]

STL std::string form.

Definition at line 658 of file tinyxml.h.

References NextSiblingElement().

Referenced by NextSiblingElement().

const TiXmlElement* TiXmlNode::NextSiblingElement ( const std::string &  _value  )  const [inline]

STL std::string form.

Definition at line 657 of file tinyxml.h.

References NextSiblingElement().

Referenced by NextSiblingElement().

TiXmlElement* TiXmlNode::NextSiblingElement ( const char *  _next  )  [inline]

Definition at line 652 of file tinyxml.h.

00652                                                               {
00653                 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00654         }

const TiXmlElement * TiXmlNode::NextSiblingElement ( const char *  _value  )  const

Convenience function to get through elements. Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns 0 if there is not another element.

Definition at line 462 of file tinyxml.cpp.

References NextSibling(), and ToElement().

00463 {
00464         const TiXmlNode* node;
00465 
00466         for (   node = NextSibling( _value );
00467                         node;
00468                         node = node->NextSibling( _value ) )
00469         {
00470                 if ( node->ToElement() )
00471                         return node->ToElement();
00472         }
00473         return 0;
00474 }

TiXmlElement* TiXmlNode::NextSiblingElement (  )  [inline]

Definition at line 643 of file tinyxml.h.

00643                                            {
00644                 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00645         }

const TiXmlElement * TiXmlNode::NextSiblingElement (  )  const

Convenience function to get through elements. Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns 0 if there is not another element.

Definition at line 447 of file tinyxml.cpp.

References NextSibling(), and ToElement().

Referenced by TiXmlHandle::ChildElement().

00448 {
00449         const TiXmlNode* node;
00450 
00451         for (   node = NextSibling();
00452                         node;
00453                         node = node->NextSibling() )
00454         {
00455                 if ( node->ToElement() )
00456                         return node->ToElement();
00457         }
00458         return 0;
00459 }

bool TiXmlNode::NoChildren (  )  const [inline]

Returns true if this node has no children.

Definition at line 693 of file tinyxml.h.

References firstChild.

00693 { return !firstChild; }

void TiXmlNode::operator= ( const TiXmlNode base  )  [private]
const TiXmlNode* TiXmlNode::Parent (  )  const [inline]

Definition at line 518 of file tinyxml.h.

References parent.

00518 { return parent; }

TiXmlNode* TiXmlNode::Parent (  )  [inline]

One step up the DOM.

Definition at line 517 of file tinyxml.h.

References parent.

00517 { return parent; }

TiXmlNode* TiXmlNode::PreviousSibling ( const std::string &  _value  )  [inline]

STL std::string form.

Definition at line 623 of file tinyxml.h.

References PreviousSibling().

Referenced by PreviousSibling().

const TiXmlNode* TiXmlNode::PreviousSibling ( const std::string &  _value  )  const [inline]

STL std::string form.

Definition at line 622 of file tinyxml.h.

References PreviousSibling().

Referenced by PreviousSibling().

TiXmlNode* TiXmlNode::PreviousSibling ( const char *  _prev  )  [inline]

Definition at line 617 of file tinyxml.h.

00617                                                         {
00618                 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00619         }

const TiXmlNode * TiXmlNode::PreviousSibling ( const char *  _value  )  const

Navigate to a sibling node.

Definition at line 390 of file tinyxml.cpp.

References prev, and Value().

00391 {
00392         const TiXmlNode* node;
00393         for ( node = prev; node; node = node->prev )
00394         {
00395                 if ( strcmp( node->Value(), _value ) == 0 )
00396                         return node;
00397         }
00398         return 0;
00399 }

TiXmlNode* TiXmlNode::PreviousSibling (  )  [inline]

Definition at line 613 of file tinyxml.h.

References prev.

00613 { return prev; }

const TiXmlNode* TiXmlNode::PreviousSibling (  )  const [inline]

Navigate to a sibling node.

Definition at line 612 of file tinyxml.h.

References prev.

00612 { return prev; }

bool TiXmlNode::RemoveChild ( TiXmlNode removeThis  ) 

Delete a child of this node.

Definition at line 304 of file tinyxml.cpp.

References firstChild, lastChild, next, parent, and prev.

00305 {
00306         if ( removeThis->parent != this )
00307         {       
00308                 assert( 0 );
00309                 return false;
00310         }
00311 
00312         if ( removeThis->next )
00313                 removeThis->next->prev = removeThis->prev;
00314         else
00315                 lastChild = removeThis->prev;
00316 
00317         if ( removeThis->prev )
00318                 removeThis->prev->next = removeThis->next;
00319         else
00320                 firstChild = removeThis->next;
00321 
00322         delete removeThis;
00323         return true;
00324 }

TiXmlNode * TiXmlNode::ReplaceChild ( TiXmlNode replaceThis,
const TiXmlNode withThis 
)

Replace a child of this node. Returns a pointer to the new object or NULL if an error occured.

Definition at line 276 of file tinyxml.cpp.

References Clone(), firstChild, lastChild, next, parent, and prev.

00277 {
00278         if ( replaceThis->parent != this )
00279                 return 0;
00280 
00281         TiXmlNode* node = withThis.Clone();
00282         if ( !node )
00283                 return 0;
00284 
00285         node->next = replaceThis->next;
00286         node->prev = replaceThis->prev;
00287 
00288         if ( replaceThis->next )
00289                 replaceThis->next->prev = node;
00290         else
00291                 lastChild = node;
00292 
00293         if ( replaceThis->prev )
00294                 replaceThis->prev->next = node;
00295         else
00296                 firstChild = node;
00297 
00298         delete replaceThis;
00299         node->parent = this;
00300         return node;
00301 }

void TiXmlNode::SetValue ( const std::string &  _value  )  [inline]

STL std::string form.

Definition at line 510 of file tinyxml.h.

00510 { value = _value; }

void TiXmlNode::SetValue ( const char *  _value  )  [inline]

Changes the value of the node. Defined as:

		Document:	filename of the xml file
		Element:	name of the element
		Comment:	the comment text
		Unknown:	the tag contents
		Text:		the text string
		

Definition at line 506 of file tinyxml.h.

References value.

Referenced by CopyTo(), TiXmlComment::TiXmlComment(), and TiXmlText::TiXmlText().

00506 { value = _value;}

virtual void TiXmlNode::StreamIn ( std::istream *  in,
TIXML_STRING *  tag 
) [protected, pure virtual]
virtual TiXmlComment* TiXmlNode::ToComment (  )  [inline, virtual]

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

Reimplemented in TiXmlComment.

Definition at line 704 of file tinyxml.h.

virtual const TiXmlComment* TiXmlNode::ToComment (  )  const [inline, virtual]

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

Reimplemented in TiXmlComment.

Definition at line 697 of file tinyxml.h.

virtual TiXmlDeclaration* TiXmlNode::ToDeclaration (  )  [inline, virtual]

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

Reimplemented in TiXmlDeclaration.

Definition at line 707 of file tinyxml.h.

virtual const TiXmlDeclaration* TiXmlNode::ToDeclaration (  )  const [inline, virtual]

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

Reimplemented in TiXmlDeclaration.

Definition at line 700 of file tinyxml.h.

Referenced by TiXmlDocument::Parse().

virtual TiXmlDocument* TiXmlNode::ToDocument (  )  [inline, virtual]

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

Reimplemented in TiXmlDocument.

Definition at line 702 of file tinyxml.h.

virtual const TiXmlDocument* TiXmlNode::ToDocument (  )  const [inline, virtual]

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

Reimplemented in TiXmlDocument.

Definition at line 695 of file tinyxml.h.

Referenced by GetDocument().

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

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

Reimplemented in TiXmlElement.

Definition at line 703 of file tinyxml.h.

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

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

Reimplemented in TiXmlElement.

Definition at line 696 of file tinyxml.h.

Referenced by FirstChildElement(), NextSiblingElement(), TiXmlDocument::StreamIn(), and TiXmlHandle::ToElement().

virtual TiXmlText* TiXmlNode::ToText (  )  [inline, virtual]

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

Reimplemented in TiXmlText.

Definition at line 706 of file tinyxml.h.

virtual const TiXmlText* TiXmlNode::ToText (  )  const [inline, virtual]

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

Reimplemented in TiXmlText.

Definition at line 699 of file tinyxml.h.

Referenced by TiXmlElement::GetText(), TiXmlElement::Print(), TiXmlHandle::ToText(), and TiXmlPrinter::VisitEnter().

virtual TiXmlUnknown* TiXmlNode::ToUnknown (  )  [inline, virtual]

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

Reimplemented in TiXmlUnknown.

Definition at line 705 of file tinyxml.h.

virtual const TiXmlUnknown* TiXmlNode::ToUnknown (  )  const [inline, virtual]

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

Reimplemented in TiXmlUnknown.

Definition at line 698 of file tinyxml.h.

Referenced by TiXmlHandle::ToUnknown().

int TiXmlNode::Type (  )  const [inline]

Query the type (as an enumerated value, above) of this node. The possible types are: DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, and DECLARATION.

Definition at line 682 of file tinyxml.h.

References type.

Referenced by InsertAfterChild(), InsertBeforeChild(), InsertEndChild(), and LinkEndChild().

00682 { return type; }

const char* TiXmlNode::Value (  )  const [inline]

The meaning of 'value' changes for the specific type of TiXmlNode.

		Document:	filename of the xml file
		Element:	name of the element
		Comment:	the comment text
		Unknown:	the tag contents
		Text:		the text string
		

The subclasses will wrap this function.

Definition at line 487 of file tinyxml.h.

References value.

Referenced by TiXmlElement::Clone(), FirstChild(), TiXmlElement::GetText(), LastChild(), TiXmlDocument::LoadFile(), NextSibling(), PreviousSibling(), Anp::HistMan::ReadHistogram(), TiXmlDocument::SaveFile(), TiXmlPrinter::Visit(), TiXmlPrinter::VisitEnter(), and TiXmlPrinter::VisitExit().

00487 { return value.c_str (); }

const std::string& TiXmlNode::ValueStr (  )  const [inline]

Return Value() as a std::string. If you only use STL, this is more efficient than calling Value(). Only available in STL mode.

Definition at line 494 of file tinyxml.h.

References value.

00494 { return value; }


Friends And Related Function Documentation

std::string& operator<< ( std::string &  out,
const TiXmlNode base 
) [friend]

Appends the XML node or attribute to a std::string.

std::ostream& operator<< ( std::ostream &  out,
const TiXmlNode base 
) [friend]

An output stream operator, for every class. Note that this outputs without any newlines or formatting, as opposed to Print(), which includes tabs and new lines.

The operator<< and operator>> are not completely symmetric. Writing a node to a stream is very well defined. You'll get a nice stream of output, without any extra whitespace or newlines.

But reading is not as well defined. (As it always is.) If you create a TiXmlElement (for example) and read that from an input stream, the text needs to define an element or junk will result. This is true of all input streams, but it's worth keeping in mind.

A TiXmlDocument will read nodes until it reads a root element, and all the children of that root element.

std::istream& operator>> ( std::istream &  in,
TiXmlNode base 
) [friend]

An input stream operator, for every class. Tolerant of newlines and formatting, but doesn't expect them.

friend class TiXmlDocument [friend]

Reimplemented from TiXmlBase.

Definition at line 425 of file tinyxml.h.

friend class TiXmlElement [friend]

Reimplemented from TiXmlBase.

Reimplemented in TiXmlText.

Definition at line 426 of file tinyxml.h.

Referenced by Identify().


Member Data Documentation

TiXmlNode* TiXmlNode::next [protected]
TiXmlNode* TiXmlNode::prev [protected]

Definition at line 754 of file tinyxml.h.

Referenced by TiXmlNode(), and Type().

TIXML_STRING TiXmlNode::value [protected]

The documentation for this class was generated from the following files:

Generated on 3 Oct 2018 for loon by  doxygen 1.6.1