xmlTiny::TiXmlNode Class Reference

The parent class for everything in the Document Object Model. More...

#include <OBTtinyxml.h>

Inheritance diagram for xmlTiny::TiXmlNode:
[legend]
Collaboration diagram for xmlTiny::TiXmlNode:
[legend]

List of all members.

Public Types

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

The types of XML nodes supported by TinyXml.

More...

Public Member Functions

virtual ~TiXmlNode ()
const char * Value () const
 The meaning of 'value' changes for the specific type of TiXmlNode.
const TIXML_STRING & ValueTStr () const
void SetValue (const char *_value)
 Changes the value of the node.
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
 The first child of this node with the matching 'value'.
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 TiXmlNodeIterateChildren (const TiXmlNode *previous) const
 An alternate way to walk the children of a node.
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)
TiXmlNodeInsertEndChild (const TiXmlNode &addThis)
 Add a new node related to this.
TiXmlNodeLinkEndChild (TiXmlNode *addThis)
 Add a new node related to this.
TiXmlNodeInsertBeforeChild (TiXmlNode *beforeThis, const TiXmlNode &addThis)
 Add a new node related to this.
TiXmlNodeInsertAfterChild (TiXmlNode *afterThis, const TiXmlNode &addThis)
 Add a new node related to this.
TiXmlNodeReplaceChild (TiXmlNode *replaceThis, const TiXmlNode &withThis)
 Replace a child of this node.
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 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
 Convenience function to get through elements.
TiXmlElementNextSiblingElement ()
const TiXmlElementNextSiblingElement (const char *) const
 Convenience function to get through elements.
TiXmlElementNextSiblingElement (const char *_next)
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)
int Type () const
 Query the type (as an enumerated value, above) of this node.
const TiXmlDocumentGetDocument () const
 Return a pointer to the Document this node lives in.
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
 Create an exact duplicate of this node and return it.
virtual bool Accept (TiXmlVisitor *visitor) const =0
 Accept a hierchical visit the nodes in the TinyXML DOM.

Protected Member Functions

 TiXmlNode (NodeType _type)
void CopyTo (TiXmlNode *target) const
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

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 430 of file tiny/tmp/OBTtinyxml.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 469 of file tiny/tmp/OBTtinyxml.h.

00470         {
00471                 DOCUMENT,
00472                 ELEMENT,
00473                 COMMENT,
00474                 UNKNOWN,
00475                 TEXT,
00476                 DECLARATION,
00477                 TYPECOUNT
00478         };


Constructor & Destructor Documentation

xmlTiny::TiXmlNode::~TiXmlNode (  )  [virtual]

Definition at line 149 of file tiny/tmp/OBTtinyxml.cpp.

References firstChild, and next.

00150 {
00151         TiXmlNode* node = firstChild;
00152         TiXmlNode* temp = 0;
00153 
00154         while ( node )
00155         {
00156                 temp = node;
00157                 node = node->next;
00158                 delete temp;
00159         }       
00160 }

xmlTiny::TiXmlNode::TiXmlNode ( NodeType  _type  )  [protected]

Definition at line 138 of file tiny/tmp/OBTtinyxml.cpp.

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

00138                                      : TiXmlBase()
00139 {
00140         parent = 0;
00141         type = _type;
00142         firstChild = 0;
00143         lastChild = 0;
00144         prev = 0;
00145         next = 0;
00146 }

xmlTiny::TiXmlNode::TiXmlNode ( const TiXmlNode  )  [private]

Member Function Documentation

virtual bool xmlTiny::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 xmlTiny::TiXmlElement, xmlTiny::TiXmlComment, xmlTiny::TiXmlText, xmlTiny::TiXmlDeclaration, xmlTiny::TiXmlUnknown, and xmlTiny::TiXmlDocument.

void xmlTiny::TiXmlNode::Clear (  ) 

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

Definition at line 170 of file tiny/tmp/OBTtinyxml.cpp.

References firstChild, lastChild, and next.

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

00171 {
00172         TiXmlNode* node = firstChild;
00173         TiXmlNode* temp = 0;
00174 
00175         while ( node )
00176         {
00177                 temp = node;
00178                 node = node->next;
00179                 delete temp;
00180         }       
00181 
00182         firstChild = 0;
00183         lastChild = 0;
00184 }

virtual TiXmlNode* xmlTiny::TiXmlNode::Clone (  )  const [pure virtual]
void xmlTiny::TiXmlNode::CopyTo ( TiXmlNode target  )  const [protected]

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

Definition at line 163 of file tiny/tmp/OBTtinyxml.cpp.

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

00164 {
00165         target->SetValue (value.c_str() );
00166         target->userData = userData; 
00167 }

TiXmlNode* xmlTiny::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 533 of file tiny/tmp/OBTtinyxml.h.

00533                                                      {
00534                 // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe)
00535                 // call the method, cast the return back to non-const.
00536                 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00537         }

const TiXmlNode * xmlTiny::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 343 of file tiny/tmp/OBTtinyxml.cpp.

References firstChild, next, and Value().

00344 {
00345         const TiXmlNode* node;
00346         for ( node = firstChild; node; node = node->next )
00347         {
00348                 if ( strcmp( node->Value(), _value ) == 0 )
00349                         return node;
00350         }
00351         return 0;
00352 }

TiXmlNode* xmlTiny::TiXmlNode::FirstChild (  )  [inline]

Definition at line 530 of file tiny/tmp/OBTtinyxml.h.

References firstChild.

00530 { return firstChild; }

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

Definition at line 678 of file tiny/tmp/OBTtinyxml.h.

00678                                                                {
00679                 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00680         }

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

Convenience function to get through elements.

Definition at line 449 of file tiny/tmp/OBTtinyxml.cpp.

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

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

TiXmlElement* xmlTiny::TiXmlNode::FirstChildElement (  )  [inline]

Definition at line 672 of file tiny/tmp/OBTtinyxml.h.

00672                                           {
00673                 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00674         }

const TiXmlElement * xmlTiny::TiXmlNode::FirstChildElement (  )  const

Convenience function to get through elements.

Definition at line 434 of file tiny/tmp/OBTtinyxml.cpp.

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

Referenced by xmlTiny::main(), and xmlTiny::TiXmlDocument::RootElement().

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

TiXmlDocument* xmlTiny::TiXmlNode::GetDocument (  )  [inline]

Definition at line 697 of file tiny/tmp/OBTtinyxml.h.

00697                                      {
00698                 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00699         }

const TiXmlDocument * xmlTiny::TiXmlNode::GetDocument (  )  const

Return a pointer to the Document this node lives in.

Returns null if not in a document.

Definition at line 494 of file tiny/tmp/OBTtinyxml.cpp.

References parent, and ToDocument().

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

00495 {
00496         const TiXmlNode* node;
00497 
00498         for( node = this; node; node = node->parent )
00499         {
00500                 if ( node->ToDocument() )
00501                         return node->ToDocument();
00502         }
00503         return 0;
00504 }

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

Definition at line 820 of file tiny/tmp/OBTtinyxmlparser.cpp.

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

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

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

TiXmlNode * xmlTiny::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 261 of file tiny/tmp/OBTtinyxml.cpp.

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

Referenced by xmlTiny::main().

00262 {
00263         if ( !afterThis || afterThis->parent != this ) {
00264                 return 0;
00265         }
00266         if ( addThis.Type() == TiXmlNode::DOCUMENT )
00267         {
00268                 if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
00269                 return 0;
00270         }
00271 
00272         TiXmlNode* node = addThis.Clone();
00273         if ( !node )
00274                 return 0;
00275         node->parent = this;
00276 
00277         node->prev = afterThis;
00278         node->next = afterThis->next;
00279         if ( afterThis->next )
00280         {
00281                 afterThis->next->prev = node;
00282         }
00283         else
00284         {
00285                 assert( lastChild == afterThis );
00286                 lastChild = node;
00287         }
00288         afterThis->next = node;
00289         return node;
00290 }

TiXmlNode * xmlTiny::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 229 of file tiny/tmp/OBTtinyxml.cpp.

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

Referenced by xmlTiny::main().

00230 {       
00231         if ( !beforeThis || beforeThis->parent != this ) {
00232                 return 0;
00233         }
00234         if ( addThis.Type() == TiXmlNode::DOCUMENT )
00235         {
00236                 if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
00237                 return 0;
00238         }
00239 
00240         TiXmlNode* node = addThis.Clone();
00241         if ( !node )
00242                 return 0;
00243         node->parent = this;
00244 
00245         node->next = beforeThis;
00246         node->prev = beforeThis->prev;
00247         if ( beforeThis->prev )
00248         {
00249                 beforeThis->prev->next = node;
00250         }
00251         else
00252         {
00253                 assert( firstChild == beforeThis );
00254                 firstChild = node;
00255         }
00256         beforeThis->prev = node;
00257         return node;
00258 }

TiXmlNode * xmlTiny::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 214 of file tiny/tmp/OBTtinyxml.cpp.

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

Referenced by xmlTiny::main().

00215 {
00216         if ( addThis.Type() == TiXmlNode::DOCUMENT )
00217         {
00218                 if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
00219                 return 0;
00220         }
00221         TiXmlNode* node = addThis.Clone();
00222         if ( !node )
00223                 return 0;
00224 
00225         return LinkEndChild( node );
00226 }

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

Definition at line 576 of file tiny/tmp/OBTtinyxml.h.

00576                                                                                      {
00577                 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00578         }

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

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

Definition at line 381 of file tiny/tmp/OBTtinyxml.cpp.

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

00382 {
00383         if ( !previous )
00384         {
00385                 return FirstChild( val );
00386         }
00387         else
00388         {
00389                 assert( previous->parent == this );
00390                 return previous->NextSibling( val );
00391         }
00392 }

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

Definition at line 570 of file tiny/tmp/OBTtinyxml.h.

00570                                                                 {
00571                 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00572         }

const TiXmlNode * xmlTiny::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 367 of file tiny/tmp/OBTtinyxml.cpp.

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

00368 {
00369         if ( !previous )
00370         {
00371                 return FirstChild();
00372         }
00373         else
00374         {
00375                 assert( previous->parent == this );
00376                 return previous->NextSibling();
00377         }
00378 }

TiXmlNode* xmlTiny::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 542 of file tiny/tmp/OBTtinyxml.h.

00542                                                     {
00543                 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00544         }

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

Definition at line 355 of file tiny/tmp/OBTtinyxml.cpp.

References lastChild, prev, and Value().

00356 {
00357         const TiXmlNode* node;
00358         for ( node = lastChild; node; node = node->prev )
00359         {
00360                 if ( strcmp( node->Value(), _value ) == 0 )
00361                         return node;
00362         }
00363         return 0;
00364 }

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

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

Definition at line 539 of file tiny/tmp/OBTtinyxml.h.

References lastChild.

00539 { return lastChild; }

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

Definition at line 538 of file tiny/tmp/OBTtinyxml.h.

References lastChild.

Referenced by xmlTiny::main(), and xmlTiny::TiXmlPrinter::VisitEnter().

00538 { return lastChild; }           

TiXmlNode * xmlTiny::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 187 of file tiny/tmp/OBTtinyxml.cpp.

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

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

00188 {
00189         assert( node->parent == 0 || node->parent == this );
00190         assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() );
00191 
00192         if ( node->Type() == TiXmlNode::DOCUMENT )
00193         {
00194                 delete node;
00195                 if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
00196                 return 0;
00197         }
00198 
00199         node->parent = this;
00200 
00201         node->prev = lastChild;
00202         node->next = 0;
00203 
00204         if ( lastChild )
00205                 lastChild->next = node;
00206         else
00207                 firstChild = node;                      // it was an empty list.
00208 
00209         lastChild = node;
00210         return node;
00211 }

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

Definition at line 643 of file tiny/tmp/OBTtinyxml.h.

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

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

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

Definition at line 395 of file tiny/tmp/OBTtinyxml.cpp.

References next, and Value().

00396 {
00397         const TiXmlNode* node;
00398         for ( node = next; node; node = node->next )
00399         {
00400                 if ( strcmp( node->Value(), _value ) == 0 )
00401                         return node;
00402         }
00403         return 0;
00404 }

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

Definition at line 639 of file tiny/tmp/OBTtinyxml.h.

References next.

00639 { return next; }

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

Definition at line 661 of file tiny/tmp/OBTtinyxml.h.

00661                                                               {
00662                 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00663         }

const TiXmlElement * xmlTiny::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 479 of file tiny/tmp/OBTtinyxml.cpp.

References NextSibling(), and ToElement().

00480 {
00481         const TiXmlNode* node;
00482 
00483         for (   node = NextSibling( _value );
00484                         node;
00485                         node = node->NextSibling( _value ) )
00486         {
00487                 if ( node->ToElement() )
00488                         return node->ToElement();
00489         }
00490         return 0;
00491 }

TiXmlElement* xmlTiny::TiXmlNode::NextSiblingElement (  )  [inline]

Definition at line 652 of file tiny/tmp/OBTtinyxml.h.

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

const TiXmlElement * xmlTiny::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 464 of file tiny/tmp/OBTtinyxml.cpp.

References NextSibling(), and ToElement().

Referenced by xmlTiny::TiXmlHandle::ChildElement(), and xmlTiny::main().

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

bool xmlTiny::TiXmlNode::NoChildren (  )  const [inline]

Returns true if this node has no children.

Definition at line 702 of file tiny/tmp/OBTtinyxml.h.

References firstChild.

00702 { return !firstChild; }

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

Definition at line 527 of file tiny/tmp/OBTtinyxml.h.

References parent.

00527 { return parent; }

TiXmlNode* xmlTiny::TiXmlNode::Parent (  )  [inline]

One step up the DOM.

Definition at line 526 of file tiny/tmp/OBTtinyxml.h.

References parent.

00526 { return parent; }

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

Definition at line 626 of file tiny/tmp/OBTtinyxml.h.

00626                                                         {
00627                 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00628         }

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

Navigate to a sibling node.

Definition at line 407 of file tiny/tmp/OBTtinyxml.cpp.

References prev, and Value().

00408 {
00409         const TiXmlNode* node;
00410         for ( node = prev; node; node = node->prev )
00411         {
00412                 if ( strcmp( node->Value(), _value ) == 0 )
00413                         return node;
00414         }
00415         return 0;
00416 }

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

Definition at line 622 of file tiny/tmp/OBTtinyxml.h.

References prev.

00622 { return prev; }

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

Navigate to a sibling node.

Definition at line 621 of file tiny/tmp/OBTtinyxml.h.

References prev.

Referenced by xmlTiny::main().

00621 { return prev; }

bool xmlTiny::TiXmlNode::RemoveChild ( TiXmlNode removeThis  ) 

Delete a child of this node.

Definition at line 321 of file tiny/tmp/OBTtinyxml.cpp.

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

Referenced by xmlTiny::main().

00322 {
00323         if ( removeThis->parent != this )
00324         {       
00325                 assert( 0 );
00326                 return false;
00327         }
00328 
00329         if ( removeThis->next )
00330                 removeThis->next->prev = removeThis->prev;
00331         else
00332                 lastChild = removeThis->prev;
00333 
00334         if ( removeThis->prev )
00335                 removeThis->prev->next = removeThis->next;
00336         else
00337                 firstChild = removeThis->next;
00338 
00339         delete removeThis;
00340         return true;
00341 }

TiXmlNode * xmlTiny::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 293 of file tiny/tmp/OBTtinyxml.cpp.

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

00294 {
00295         if ( replaceThis->parent != this )
00296                 return 0;
00297 
00298         TiXmlNode* node = withThis.Clone();
00299         if ( !node )
00300                 return 0;
00301 
00302         node->next = replaceThis->next;
00303         node->prev = replaceThis->prev;
00304 
00305         if ( replaceThis->next )
00306                 replaceThis->next->prev = node;
00307         else
00308                 lastChild = node;
00309 
00310         if ( replaceThis->prev )
00311                 replaceThis->prev->next = node;
00312         else
00313                 firstChild = node;
00314 
00315         delete replaceThis;
00316         node->parent = this;
00317         return node;
00318 }

void xmlTiny::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 515 of file tiny/tmp/OBTtinyxml.h.

References value.

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

00515 { value = _value;}

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

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

Reimplemented in xmlTiny::TiXmlComment.

Definition at line 713 of file tiny/tmp/OBTtinyxml.h.

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

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

Reimplemented in xmlTiny::TiXmlComment.

Definition at line 706 of file tiny/tmp/OBTtinyxml.h.

Referenced by xmlTiny::main().

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

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

Reimplemented in xmlTiny::TiXmlDeclaration.

Definition at line 716 of file tiny/tmp/OBTtinyxml.h.

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

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

Reimplemented in xmlTiny::TiXmlDeclaration.

Definition at line 709 of file tiny/tmp/OBTtinyxml.h.

Referenced by xmlTiny::main(), and xmlTiny::TiXmlDocument::Parse().

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

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

Reimplemented in xmlTiny::TiXmlDocument.

Definition at line 711 of file tiny/tmp/OBTtinyxml.h.

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

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

Reimplemented in xmlTiny::TiXmlDocument.

Definition at line 704 of file tiny/tmp/OBTtinyxml.h.

Referenced by GetDocument().

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

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

Reimplemented in xmlTiny::TiXmlElement.

Definition at line 712 of file tiny/tmp/OBTtinyxml.h.

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

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

Reimplemented in xmlTiny::TiXmlElement.

Definition at line 705 of file tiny/tmp/OBTtinyxml.h.

Referenced by FirstChildElement(), xmlTiny::main(), and NextSiblingElement().

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

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

Reimplemented in xmlTiny::TiXmlText.

Definition at line 715 of file tiny/tmp/OBTtinyxml.h.

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

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

Reimplemented in xmlTiny::TiXmlText.

Definition at line 708 of file tiny/tmp/OBTtinyxml.h.

Referenced by xmlTiny::TiXmlElement::GetText(), xmlTiny::main(), xmlTiny::TiXmlElement::Print(), and xmlTiny::TiXmlPrinter::VisitEnter().

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

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

Reimplemented in xmlTiny::TiXmlUnknown.

Definition at line 714 of file tiny/tmp/OBTtinyxml.h.

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

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

Reimplemented in xmlTiny::TiXmlUnknown.

Definition at line 707 of file tiny/tmp/OBTtinyxml.h.

int xmlTiny::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 691 of file tiny/tmp/OBTtinyxml.h.

References type.

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

00691 { return type; }

const char* xmlTiny::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 494 of file tiny/tmp/OBTtinyxml.h.

References value.

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

00494 { return value.c_str (); }

const TIXML_STRING& xmlTiny::TiXmlNode::ValueTStr (  )  const [inline]

Definition at line 504 of file tiny/tmp/OBTtinyxml.h.

References value.

Referenced by xmlTiny::TiXmlPrinter::Visit().

00504 { return value; }


Friends And Related Function Documentation

friend class TiXmlDocument [friend]

Reimplemented from xmlTiny::TiXmlBase.

Definition at line 432 of file tiny/tmp/OBTtinyxml.h.

friend class TiXmlElement [friend]

Reimplemented from xmlTiny::TiXmlBase.

Reimplemented in xmlTiny::TiXmlText.

Definition at line 433 of file tiny/tmp/OBTtinyxml.h.

Referenced by Identify().


Member Data Documentation

Definition at line 763 of file tiny/tmp/OBTtinyxml.h.

Referenced by TiXmlNode(), and Type().

TIXML_STRING xmlTiny::TiXmlNode::value [protected]

Generated on 1 Jan 2010 for OBT by  doxygen 1.6.1