OBT::TiXmlElement Class Reference

The element is a container class. More...

#include <OBTtinyxml.h>

Inheritance diagram for OBT::TiXmlElement:
[legend]
Collaboration diagram for OBT::TiXmlElement:
[legend]

List of all members.

Public Member Functions

 TiXmlElement (const char *in_value)
 Construct an element.
 TiXmlElement (const TiXmlElement &)
void operator= (const TiXmlElement &base)
virtual ~TiXmlElement ()
const char * Attribute (const char *name) const
 Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
const char * Attribute (const char *name, int *i) const
 Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
const char * Attribute (const char *name, double *d) const
 Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
int QueryIntAttribute (const char *name, int *_value) const
 QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking.
int QueryDoubleAttribute (const char *name, double *_value) const
 QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
int QueryFloatAttribute (const char *name, float *_value) const
 QueryFloatAttribute examines the attribute - see QueryIntAttribute().
void SetAttribute (const char *name, const char *_value)
 Sets an attribute of name to a given value.
void SetAttribute (const char *name, int value)
 Sets an attribute of name to a given value.
void SetDoubleAttribute (const char *name, double value)
 Sets an attribute of name to a given value.
void RemoveAttribute (const char *name)
 Deletes an attribute with the given name.
const TiXmlAttributeFirstAttribute () const
 Access the first attribute in this element.
TiXmlAttributeFirstAttribute ()
const TiXmlAttributeLastAttribute () const
 Access the last attribute in this element.
TiXmlAttributeLastAttribute ()
const char * GetText () const
 Convenience function for easy access to the text inside an element.
virtual TiXmlNodeClone () const
 Creates a new Element and returns it - the returned element is a copy.
virtual void Print (FILE *cfile, int depth) const
 All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.
virtual const char * Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlElementToElement () const
 Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlElementToElement ()
 Cast to a more defined type. Will return null not of the requested type.
virtual bool Accept (TiXmlVisitor *visitor) const
 Walk the XML tree visiting this node and all of its children.
 TiXmlElement (const char *in_value)
 Construct an element.
 TiXmlElement (const TiXmlElement &)
void operator= (const TiXmlElement &base)
virtual ~TiXmlElement ()
const char * Attribute (const char *name) const
 Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
const char * Attribute (const char *name, int *i) const
 Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
const char * Attribute (const char *name, double *d) const
 Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
int QueryIntAttribute (const char *name, int *_value) const
 QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking.
int QueryDoubleAttribute (const char *name, double *_value) const
 QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
int QueryFloatAttribute (const char *name, float *_value) const
 QueryFloatAttribute examines the attribute - see QueryIntAttribute().
void SetAttribute (const char *name, const char *_value)
 Sets an attribute of name to a given value.
void SetAttribute (const char *name, int value)
 Sets an attribute of name to a given value.
void SetDoubleAttribute (const char *name, double value)
 Sets an attribute of name to a given value.
void RemoveAttribute (const char *name)
 Deletes an attribute with the given name.
const TiXmlAttributeFirstAttribute () const
 Access the first attribute in this element.
TiXmlAttributeFirstAttribute ()
const TiXmlAttributeLastAttribute () const
 Access the last attribute in this element.
TiXmlAttributeLastAttribute ()
const char * GetText () const
 Convenience function for easy access to the text inside an element.
virtual TiXmlNodeClone () const
 Creates a new Element and returns it - the returned element is a copy.
virtual void Print (FILE *cfile, int depth) const
 All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.
virtual const char * Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlElementToElement () const
 Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlElementToElement ()
 Cast to a more defined type. Will return null not of the requested type.
virtual bool Accept (TiXmlVisitor *visitor) const
 Walk the XML tree visiting this node and all of its children.

Protected Member Functions

void CopyTo (TiXmlElement *target) const
void ClearThis ()
const char * ReadValue (const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
void CopyTo (TiXmlElement *target) const
void ClearThis ()
const char * ReadValue (const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)

Private Attributes

TiXmlAttributeSet attributeSet

Detailed Description

The element is a container class.

It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes.

Definition at line 951 of file OBTtinyxml.h.


Constructor & Destructor Documentation

OBT::TiXmlElement::TiXmlElement ( const char *  in_value  ) 

Construct an element.

Definition at line 506 of file OBTtinyxml.cpp.

References OBT::TiXmlNode::firstChild, OBT::TiXmlNode::lastChild, and OBT::TiXmlNode::value.

Referenced by Clone().

00507         : TiXmlNode( TiXmlNode::ELEMENT )
00508 {
00509         firstChild = lastChild = 0;
00510         value = _value;
00511 }

OBT::TiXmlElement::TiXmlElement ( const TiXmlElement copy  ) 

Definition at line 524 of file OBTtinyxml.cpp.

References CopyTo(), OBT::TiXmlNode::firstChild, and OBT::TiXmlNode::lastChild.

00525         : TiXmlNode( TiXmlNode::ELEMENT )
00526 {
00527         firstChild = lastChild = 0;
00528         copy.CopyTo( this );    
00529 }

OBT::TiXmlElement::~TiXmlElement (  )  [virtual]

Definition at line 539 of file OBTtinyxml.cpp.

References ClearThis().

00540 {
00541         ClearThis();
00542 }

OBT::TiXmlElement::TiXmlElement ( const char *  in_value  ) 

Construct an element.

OBT::TiXmlElement::TiXmlElement ( const TiXmlElement  ) 
virtual OBT::TiXmlElement::~TiXmlElement (  )  [virtual]

Member Function Documentation

virtual bool OBT::TiXmlElement::Accept ( TiXmlVisitor visitor  )  const [virtual]

Walk the XML tree visiting this node and all of its children.

Implements OBT::TiXmlNode.

bool OBT::TiXmlElement::Accept ( TiXmlVisitor visitor  )  const [virtual]

Walk the XML tree visiting this node and all of its children.

Implements OBT::TiXmlNode.

Definition at line 848 of file OBTtinyxml.cpp.

References attributeSet, OBT::TiXmlAttributeSet::First(), OBT::TiXmlNode::FirstChild(), OBT::TiXmlVisitor::VisitEnter(), and OBT::TiXmlVisitor::VisitExit().

00849 {
00850         if ( visitor->VisitEnter( *this, attributeSet.First() ) ) 
00851         {
00852                 for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
00853                 {
00854                         if ( !node->Accept( visitor ) )
00855                                 break;
00856                 }
00857         }
00858         return visitor->VisitExit( *this );
00859 }

const char* OBT::TiXmlElement::Attribute ( const char *  name,
double *  d 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

If the attribute exists and can be converted to an double, the double value will be put in the return 'd', if 'd' is non-null.

const char* OBT::TiXmlElement::Attribute ( const char *  name,
int *  i 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

If the attribute exists and can be converted to an integer, the integer value will be put in the return 'i', if 'i' is non-null.

const char* OBT::TiXmlElement::Attribute ( const char *  name  )  const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

const char * OBT::TiXmlElement::Attribute ( const char *  name,
double *  d 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

If the attribute exists and can be converted to an double, the double value will be put in the return 'd', if 'd' is non-null.

Definition at line 611 of file OBTtinyxml.cpp.

References Attribute().

00612 {
00613         const char* s = Attribute( name );
00614         if ( d )
00615         {
00616                 if ( s ) {
00617                         *d = atof( s );
00618                 }
00619                 else {
00620                         *d = 0;
00621                 }
00622         }
00623         return s;
00624 }

const char * OBT::TiXmlElement::Attribute ( const char *  name,
int *  i 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

If the attribute exists and can be converted to an integer, the integer value will be put in the return 'i', if 'i' is non-null.

Definition at line 577 of file OBTtinyxml.cpp.

References Attribute().

00578 {
00579         const char* s = Attribute( name );
00580         if ( i )
00581         {
00582                 if ( s ) {
00583                         *i = atoi( s );
00584                 }
00585                 else {
00586                         *i = 0;
00587                 }
00588         }
00589         return s;
00590 }

const char * OBT::TiXmlElement::Attribute ( const char *  name  )  const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

Definition at line 557 of file OBTtinyxml.cpp.

References attributeSet, OBT::TiXmlAttributeSet::Find(), and OBT::TiXmlAttribute::Value().

Referenced by Attribute(), and OBT::main().

00558 {
00559         const TiXmlAttribute* node = attributeSet.Find( name );
00560         if ( node )
00561                 return node->Value();
00562         return 0;
00563 }

void OBT::TiXmlElement::ClearThis (  )  [protected]
void OBT::TiXmlElement::ClearThis (  )  [protected]

Definition at line 545 of file OBTtinyxml.cpp.

References attributeSet, OBT::TiXmlNode::Clear(), OBT::TiXmlAttributeSet::First(), and OBT::TiXmlAttributeSet::Remove().

Referenced by operator=(), and ~TiXmlElement().

00546 {
00547         Clear();
00548         while( attributeSet.First() )
00549         {
00550                 TiXmlAttribute* node = attributeSet.First();
00551                 attributeSet.Remove( node );
00552                 delete node;
00553         }
00554 }

virtual TiXmlNode* OBT::TiXmlElement::Clone (  )  const [virtual]

Creates a new Element and returns it - the returned element is a copy.

Implements OBT::TiXmlNode.

TiXmlNode * OBT::TiXmlElement::Clone (  )  const [virtual]

Creates a new Element and returns it - the returned element is a copy.

Implements OBT::TiXmlNode.

Definition at line 862 of file OBTtinyxml.cpp.

References CopyTo(), TiXmlElement(), and OBT::TiXmlNode::Value().

00863 {
00864         TiXmlElement* clone = new TiXmlElement( Value() );
00865         if ( !clone )
00866                 return 0;
00867 
00868         CopyTo( clone );
00869         return clone;
00870 }

void OBT::TiXmlElement::CopyTo ( TiXmlElement target  )  const [protected]

Reimplemented from OBT::TiXmlNode.

void OBT::TiXmlElement::CopyTo ( TiXmlElement target  )  const [protected]

Reimplemented from OBT::TiXmlNode.

Definition at line 826 of file OBTtinyxml.cpp.

References attributeSet, OBT::TiXmlNode::Clone(), OBT::TiXmlAttributeSet::First(), OBT::TiXmlNode::firstChild, OBT::TiXmlNode::LinkEndChild(), OBT::TiXmlAttribute::Name(), OBT::TiXmlAttribute::Next(), OBT::TiXmlNode::NextSibling(), SetAttribute(), and OBT::TiXmlAttribute::Value().

Referenced by Clone(), operator=(), and TiXmlElement().

00827 {
00828         // superclass:
00829         TiXmlNode::CopyTo( target );
00830 
00831         // Element class: 
00832         // Clone the attributes, then clone the children.
00833         const TiXmlAttribute* attribute = 0;
00834         for(    attribute = attributeSet.First();
00835         attribute;
00836         attribute = attribute->Next() )
00837         {
00838                 target->SetAttribute( attribute->Name(), attribute->Value() );
00839         }
00840 
00841         TiXmlNode* node = 0;
00842         for ( node = firstChild; node; node = node->NextSibling() )
00843         {
00844                 target->LinkEndChild( node->Clone() );
00845         }
00846 }

TiXmlAttribute* OBT::TiXmlElement::FirstAttribute (  )  [inline]

Definition at line 1082 of file tiny/OBTtinyxml.h.

References attributeSet, and OBT::TiXmlAttributeSet::First().

01082 { return attributeSet.First(); }

const TiXmlAttribute* OBT::TiXmlElement::FirstAttribute (  )  const [inline]

Access the first attribute in this element.

Definition at line 1081 of file tiny/OBTtinyxml.h.

References attributeSet, and OBT::TiXmlAttributeSet::First().

TiXmlAttribute* OBT::TiXmlElement::FirstAttribute (  )  [inline]

Definition at line 1083 of file OBTtinyxml.h.

01083 { return attributeSet.First(); }

const TiXmlAttribute* OBT::TiXmlElement::FirstAttribute (  )  const [inline]

Access the first attribute in this element.

Definition at line 1082 of file OBTtinyxml.h.

Referenced by OBT::XMLConfigurationFileParser::AddChildren(), and OBT::main().

const char* OBT::TiXmlElement::GetText (  )  const

Convenience function for easy access to the text inside an element.

Although easy and concise, GetText() is limited compared to getting the TiXmlText child and accessing it directly.

If the first child of 'this' is a TiXmlText, the GetText() returns the character string of the Text node, else null is returned.

This is a convenient method for getting the text of simple contained text:

		<foo>This is text</foo>
		const char* str = fooElement->GetText();
		

'str' will be a pointer to "This is text".

Note that this function can be misleading. If the element foo was created from this XML:

		<foo><b>This is text</b></foo> 
		

then the value of str would be null. The first child node isn't a text node, it is another element. From this XML:

		<foo>This is <b>text</b></foo> 
		

GetText() will return "This is ".

WARNING: GetText() accesses a child node - don't become confused with the similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are safe type casts on the referenced node.

const char * OBT::TiXmlElement::GetText (  )  const

Convenience function for easy access to the text inside an element.

Although easy and concise, GetText() is limited compared to getting the TiXmlText child and accessing it directly.

If the first child of 'this' is a TiXmlText, the GetText() returns the character string of the Text node, else null is returned.

This is a convenient method for getting the text of simple contained text:

		<foo>This is text</foo>
		const char* str = fooElement->GetText();
		

'str' will be a pointer to "This is text".

Note that this function can be misleading. If the element foo was created from this XML:

		<foo><b>This is text</b></foo> 
		

then the value of str would be null. The first child node isn't a text node, it is another element. From this XML:

		<foo>This is <b>text</b></foo> 
		

GetText() will return "This is ".

WARNING: GetText() accesses a child node - don't become confused with the similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are safe type casts on the referenced node.

Definition at line 873 of file OBTtinyxml.cpp.

References OBT::TiXmlNode::FirstChild(), OBT::TiXmlNode::ToText(), and OBT::TiXmlNode::Value().

Referenced by OBT::XMLConfigurationFileParser::AddChildren(), and OBT::main().

00874 {
00875         const TiXmlNode* child = this->FirstChild();
00876         if ( child ) {
00877                 const TiXmlText* childText = child->ToText();
00878                 if ( childText ) {
00879                         return childText->Value();
00880                 }
00881         }
00882         return 0;
00883 }

TiXmlAttribute* OBT::TiXmlElement::LastAttribute (  )  [inline]

Definition at line 1084 of file tiny/OBTtinyxml.h.

References attributeSet, and OBT::TiXmlAttributeSet::Last().

01084 { return attributeSet.Last(); }

const TiXmlAttribute* OBT::TiXmlElement::LastAttribute (  )  const [inline]

Access the last attribute in this element.

Definition at line 1083 of file tiny/OBTtinyxml.h.

References attributeSet, and OBT::TiXmlAttributeSet::Last().

TiXmlAttribute* OBT::TiXmlElement::LastAttribute (  )  [inline]

Definition at line 1085 of file OBTtinyxml.h.

01085 { return attributeSet.Last(); }

const TiXmlAttribute* OBT::TiXmlElement::LastAttribute (  )  const [inline]

Access the last attribute in this element.

Definition at line 1084 of file OBTtinyxml.h.

void OBT::TiXmlElement::operator= ( const TiXmlElement base  ) 

Reimplemented from OBT::TiXmlNode.

void OBT::TiXmlElement::operator= ( const TiXmlElement base  ) 

Reimplemented from OBT::TiXmlNode.

Definition at line 532 of file OBTtinyxml.cpp.

References ClearThis(), and CopyTo().

00533 {
00534         ClearThis();
00535         base.CopyTo( this );
00536 }

virtual const char* OBT::TiXmlElement::Parse ( const char *  p,
TiXmlParsingData data,
TiXmlEncoding  encoding 
) [virtual]

Implements OBT::TiXmlBase.

const char * OBT::TiXmlElement::Parse ( const char *  p,
TiXmlParsingData data,
TiXmlEncoding  encoding 
) [virtual]

Implements OBT::TiXmlBase.

Definition at line 1051 of file OBTtinyxmlparser.cpp.

References OBT::TiXmlAttributeSet::Add(), attributeSet, OBT::TiXmlParsingData::Cursor(), OBT::TiXmlAttributeSet::Find(), OBT::TiXmlNode::GetDocument(), OBT::TiXmlBase::location, OBT::TiXmlAttribute::Name(), OBT::TiXmlAttribute::NameTStr(), OBT::TiXmlAttribute::Parse(), OBT::TiXmlBase::ReadName(), ReadValue(), OBT::TiXmlAttribute::SetDocument(), OBT::TiXmlDocument::SetError(), OBT::TiXmlAttribute::setValue(), OBT::TiXmlBase::SkipWhiteSpace(), OBT::TiXmlParsingData::Stamp(), OBT::TiXmlBase::StringEqual(), OBT::TiXmlBase::TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, OBT::TiXmlBase::TIXML_ERROR_OUT_OF_MEMORY, OBT::TiXmlBase::TIXML_ERROR_PARSING_ELEMENT, OBT::TiXmlBase::TIXML_ERROR_PARSING_EMPTY, OBT::TiXmlBase::TIXML_ERROR_READING_ATTRIBUTES, OBT::TiXmlBase::TIXML_ERROR_READING_END_TAG, TIXML_STRING, OBT::TiXmlAttribute::Value(), and OBT::TiXmlNode::value.

Referenced by OBT::main().

01052 {
01053         p = SkipWhiteSpace( p, encoding );
01054         TiXmlDocument* document = GetDocument();
01055 
01056         if ( !p || !*p )
01057         {
01058                 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding );
01059                 return 0;
01060         }
01061 
01062         if ( data )
01063         {
01064                 data->Stamp( p, encoding );
01065                 location = data->Cursor();
01066         }
01067 
01068         if ( *p != '<' )
01069         {
01070                 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, p, data, encoding );
01071                 return 0;
01072         }
01073 
01074         p = SkipWhiteSpace( p+1, encoding );
01075 
01076         // Read the name.
01077         const char* pErr = p;
01078 
01079     p = ReadName( p, &value, encoding );
01080         if ( !p || !*p )
01081         {
01082                 if ( document ) document->SetError( TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding );
01083                 return 0;
01084         }
01085 
01086     TIXML_STRING endTag ("</");
01087         endTag += value;
01088         endTag += ">";
01089 
01090         // Check for and read attributes. Also look for an empty
01091         // tag or an end tag.
01092         while ( p && *p )
01093         {
01094                 pErr = p;
01095                 p = SkipWhiteSpace( p, encoding );
01096                 if ( !p || !*p )
01097                 {
01098                         if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
01099                         return 0;
01100                 }
01101                 if ( *p == '/' )
01102                 {
01103                         ++p;
01104                         // Empty tag.
01105                         if ( *p  != '>' )
01106                         {
01107                                 if ( document ) document->SetError( TIXML_ERROR_PARSING_EMPTY, p, data, encoding );             
01108                                 return 0;
01109                         }
01110                         return (p+1);
01111                 }
01112                 else if ( *p == '>' )
01113                 {
01114                         // Done with attributes (if there were any.)
01115                         // Read the value -- which can include other
01116                         // elements -- read the end tag, and return.
01117                         ++p;
01118                         p = ReadValue( p, data, encoding );             // Note this is an Element method, and will set the error if one happens.
01119                         if ( !p || !*p ) {
01120                                 // We were looking for the end tag, but found nothing.
01121                                 // Fix for [ 1663758 ] Failure to report error on bad XML
01122                                 if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
01123                                 return 0;
01124                         }
01125 
01126                         // We should find the end tag now
01127                         if ( StringEqual( p, endTag.c_str(), false, encoding ) )
01128                         {
01129                                 p += endTag.length();
01130                                 return p;
01131                         }
01132                         else
01133                         {
01134                                 if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
01135                                 return 0;
01136                         }
01137                 }
01138                 else
01139                 {
01140                         // Try to read an attribute:
01141                         TiXmlAttribute* attrib = new TiXmlAttribute();
01142                         if ( !attrib )
01143                         {
01144                                 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, pErr, data, encoding );
01145                                 return 0;
01146                         }
01147 
01148                         attrib->SetDocument( document );
01149                         pErr = p;
01150                         p = attrib->Parse( p, data, encoding );
01151 
01152                         if ( !p || !*p )
01153                         {
01154                                 if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
01155                                 delete attrib;
01156                                 return 0;
01157                         }
01158 
01159                         // Handle the strange case of double attributes:
01160                         #ifdef TIXML_USE_STL
01161                         TiXmlAttribute* node = attributeSet.Find( attrib->NameTStr() );
01162                         #else
01163                         TiXmlAttribute* node = attributeSet.Find( attrib->Name() );
01164                         #endif
01165                         if ( node )
01166                         {
01167                                 node->setValue( attrib->Value() );
01168                                 delete attrib;
01169                                 return 0;
01170                         }
01171 
01172                         attributeSet.Add( attrib );
01173                 }
01174         }
01175         return p;
01176 }

virtual void OBT::TiXmlElement::Print ( FILE *  cfile,
int  depth 
) const [virtual]

All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.

) Either or both cfile and str can be null.

This is a formatted print, and will insert tabs and newlines.

(For an unformatted stream, use the << operator.)

Implements OBT::TiXmlBase.

void OBT::TiXmlElement::Print ( FILE *  cfile,
int  depth 
) const [virtual]

All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.

) Either or both cfile and str can be null.

This is a formatted print, and will insert tabs and newlines.

(For an unformatted stream, use the << operator.)

Implements OBT::TiXmlBase.

Definition at line 773 of file OBTtinyxml.cpp.

References attributeSet, OBT::TiXmlAttributeSet::First(), OBT::TiXmlNode::firstChild, OBT::TiXmlNode::lastChild, OBT::TiXmlAttribute::Next(), OBT::TiXmlNode::NextSibling(), OBT::TiXmlBase::Print(), OBT::TiXmlNode::ToText(), and OBT::TiXmlNode::value.

Referenced by OBT::main().

00774 {
00775         int i;
00776         assert( cfile );
00777         for ( i=0; i<depth; i++ ) {
00778                 fprintf( cfile, "    " );
00779         }
00780 
00781         fprintf( cfile, "<%s", value.c_str() );
00782 
00783         const TiXmlAttribute* attrib;
00784         for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
00785         {
00786                 fprintf( cfile, " " );
00787                 attrib->Print( cfile, depth );
00788         }
00789 
00790         // There are 3 different formatting approaches:
00791         // 1) An element without children is printed as a <foo /> node
00792         // 2) An element with only a text child is printed as <foo> text </foo>
00793         // 3) An element with children is printed on multiple lines.
00794         TiXmlNode* node;
00795         if ( !firstChild )
00796         {
00797                 fprintf( cfile, " />" );
00798         }
00799         else if ( firstChild == lastChild && firstChild->ToText() )
00800         {
00801                 fprintf( cfile, ">" );
00802                 firstChild->Print( cfile, depth + 1 );
00803                 fprintf( cfile, "</%s>", value.c_str() );
00804         }
00805         else
00806         {
00807                 fprintf( cfile, ">" );
00808 
00809                 for ( node = firstChild; node; node=node->NextSibling() )
00810                 {
00811                         if ( !node->ToText() )
00812                         {
00813                                 fprintf( cfile, "\n" );
00814                         }
00815                         node->Print( cfile, depth+1 );
00816                 }
00817                 fprintf( cfile, "\n" );
00818                 for( i=0; i<depth; ++i ) {
00819                         fprintf( cfile, "    " );
00820                 }
00821                 fprintf( cfile, "</%s>", value.c_str() );
00822         }
00823 }

int OBT::TiXmlElement::QueryDoubleAttribute ( const char *  name,
double *  _value 
) const

QueryDoubleAttribute examines the attribute - see QueryIntAttribute().

int OBT::TiXmlElement::QueryDoubleAttribute ( const char *  name,
double *  _value 
) const

QueryDoubleAttribute examines the attribute - see QueryIntAttribute().

Definition at line 665 of file OBTtinyxml.cpp.

References attributeSet, OBT::TiXmlAttributeSet::Find(), OBT::TiXmlAttribute::QueryDoubleValue(), and OBT::TIXML_NO_ATTRIBUTE.

Referenced by OBT::main(), and QueryFloatAttribute().

00666 {
00667         const TiXmlAttribute* node = attributeSet.Find( name );
00668         if ( !node )
00669                 return TIXML_NO_ATTRIBUTE;
00670         return node->QueryDoubleValue( dval );
00671 }

int OBT::TiXmlElement::QueryFloatAttribute ( const char *  name,
float *  _value 
) const [inline]

QueryFloatAttribute examines the attribute - see QueryIntAttribute().

Definition at line 999 of file tiny/OBTtinyxml.h.

References QueryDoubleAttribute(), and OBT::TIXML_SUCCESS.

00999                                                                          {
01000                 double d;
01001                 int result = QueryDoubleAttribute( name, &d );
01002                 if ( result == TIXML_SUCCESS ) {
01003                         *_value = (float)d;
01004                 }
01005                 return result;
01006         }

int OBT::TiXmlElement::QueryFloatAttribute ( const char *  name,
float *  _value 
) const [inline]

QueryFloatAttribute examines the attribute - see QueryIntAttribute().

Definition at line 1000 of file OBTtinyxml.h.

References OBT::TIXML_SUCCESS.

01000                                                                          {
01001                 double d;
01002                 int result = QueryDoubleAttribute( name, &d );
01003                 if ( result == TIXML_SUCCESS ) {
01004                         *_value = (float)d;
01005                 }
01006                 return result;
01007         }

int OBT::TiXmlElement::QueryIntAttribute ( const char *  name,
int *  _value 
) const

QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking.

If the attribute is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. If the attribute does not exist, then TIXML_NO_ATTRIBUTE is returned.

int OBT::TiXmlElement::QueryIntAttribute ( const char *  name,
int *  _value 
) const

QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking.

If the attribute is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. If the attribute does not exist, then TIXML_NO_ATTRIBUTE is returned.

Definition at line 645 of file OBTtinyxml.cpp.

References attributeSet, OBT::TiXmlAttributeSet::Find(), OBT::TiXmlAttribute::QueryIntValue(), and OBT::TIXML_NO_ATTRIBUTE.

Referenced by OBT::main().

00646 {
00647         const TiXmlAttribute* node = attributeSet.Find( name );
00648         if ( !node )
00649                 return TIXML_NO_ATTRIBUTE;
00650         return node->QueryIntValue( ival );
00651 }

const char* OBT::TiXmlElement::ReadValue ( const char *  in,
TiXmlParsingData prevData,
TiXmlEncoding  encoding 
) [protected]
const char * OBT::TiXmlElement::ReadValue ( const char *  in,
TiXmlParsingData prevData,
TiXmlEncoding  encoding 
) [protected]

Definition at line 1179 of file OBTtinyxmlparser.cpp.

References OBT::TiXmlText::Blank(), OBT::TiXmlNode::GetDocument(), OBT::TiXmlNode::Identify(), OBT::TiXmlBase::IsWhiteSpaceCondensed(), OBT::TiXmlNode::LinkEndChild(), OBT::TiXmlBase::Parse(), OBT::TiXmlText::Parse(), OBT::TiXmlDocument::SetError(), OBT::TiXmlBase::SkipWhiteSpace(), OBT::TiXmlBase::StringEqual(), OBT::TiXmlBase::TIXML_ERROR_OUT_OF_MEMORY, and OBT::TiXmlBase::TIXML_ERROR_READING_ELEMENT_VALUE.

Referenced by Parse().

01180 {
01181         TiXmlDocument* document = GetDocument();
01182 
01183         // Read in text and elements in any order.
01184         const char* pWithWhiteSpace = p;
01185         p = SkipWhiteSpace( p, encoding );
01186 
01187         while ( p && *p )
01188         {
01189                 if ( *p != '<' )
01190                 {
01191                         // Take what we have, make a text element.
01192                         TiXmlText* textNode = new TiXmlText( "" );
01193 
01194                         if ( !textNode )
01195                         {
01196                                 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
01197                                     return 0;
01198                         }
01199 
01200                         if ( TiXmlBase::IsWhiteSpaceCondensed() )
01201                         {
01202                                 p = textNode->Parse( p, data, encoding );
01203                         }
01204                         else
01205                         {
01206                                 // Special case: we want to keep the white space
01207                                 // so that leading spaces aren't removed.
01208                                 p = textNode->Parse( pWithWhiteSpace, data, encoding );
01209                         }
01210 
01211                         if ( !textNode->Blank() )
01212                                 LinkEndChild( textNode );
01213                         else
01214                                 delete textNode;
01215                 } 
01216                 else 
01217                 {
01218                         // We hit a '<'
01219                         // Have we hit a new element or an end tag? This could also be
01220                         // a TiXmlText in the "CDATA" style.
01221                         if ( StringEqual( p, "</", false, encoding ) )
01222                         {
01223                                 return p;
01224                         }
01225                         else
01226                         {
01227                                 TiXmlNode* node = Identify( p, encoding );
01228                                 if ( node )
01229                                 {
01230                                         p = node->Parse( p, data, encoding );
01231                                         LinkEndChild( node );
01232                                 }                               
01233                                 else
01234                                 {
01235                                         return 0;
01236                                 }
01237                         }
01238                 }
01239                 pWithWhiteSpace = p;
01240                 p = SkipWhiteSpace( p, encoding );
01241         }
01242 
01243         if ( !p )
01244         {
01245                 if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding );
01246         }       
01247         return p;
01248 }

void OBT::TiXmlElement::RemoveAttribute ( const char *  name  ) 

Deletes an attribute with the given name.

void OBT::TiXmlElement::RemoveAttribute ( const char *  name  ) 

Deletes an attribute with the given name.

Definition at line 418 of file OBTtinyxml.cpp.

References attributeSet, OBT::TiXmlAttributeSet::Find(), OBT::TiXmlAttributeSet::Remove(), and TIXML_STRING.

00419 {
00420     #ifdef TIXML_USE_STL
00421         TIXML_STRING str( name );
00422         TiXmlAttribute* node = attributeSet.Find( str );
00423         #else
00424         TiXmlAttribute* node = attributeSet.Find( name );
00425         #endif
00426         if ( node )
00427         {
00428                 attributeSet.Remove( node );
00429                 delete node;
00430         }
00431 }

void OBT::TiXmlElement::SetAttribute ( const char *  name,
int  value 
)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

void OBT::TiXmlElement::SetAttribute ( const char *  name,
const char *  _value 
)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

void OBT::TiXmlElement::SetAttribute ( const char *  name,
int  value 
)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

Definition at line 685 of file OBTtinyxml.cpp.

References SetAttribute().

00686 {       
00687         char buf[64];
00688         #if defined(TIXML_SNPRINTF)             
00689                 TIXML_SNPRINTF( buf, sizeof(buf), "%d", val );
00690         #else
00691                 sprintf( buf, "%d", val );
00692         #endif
00693         SetAttribute( name, buf );
00694 }

void OBT::TiXmlElement::SetAttribute ( const char *  name,
const char *  _value 
)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

Definition at line 719 of file OBTtinyxml.cpp.

References OBT::TiXmlAttributeSet::Add(), attributeSet, OBT::TiXmlAttributeSet::Find(), OBT::TiXmlNode::GetDocument(), OBT::TiXmlDocument::SetError(), OBT::TiXmlAttribute::setValue(), OBT::TIXML_ENCODING_UNKNOWN, OBT::TiXmlBase::TIXML_ERROR_OUT_OF_MEMORY, and TIXML_STRING.

Referenced by CopyTo(), OBT::main(), SetAttribute(), and SetDoubleAttribute().

00720 {
00721     #ifdef TIXML_USE_STL
00722         TIXML_STRING _name( cname );
00723         TIXML_STRING _value( cvalue );
00724         #else
00725         const char* _name = cname;
00726         const char* _value = cvalue;
00727         #endif
00728 
00729         TiXmlAttribute* node = attributeSet.Find( _name );
00730         if ( node )
00731         {
00732                 node->setValue( _value );
00733                 return;
00734         }
00735 
00736         TiXmlAttribute* attrib = new TiXmlAttribute( cname, cvalue );
00737         if ( attrib )
00738         {
00739                 attributeSet.Add( attrib );
00740         }
00741         else
00742         {
00743                 TiXmlDocument* document = GetDocument();
00744                 if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN );
00745         }
00746 }

void OBT::TiXmlElement::SetDoubleAttribute ( const char *  name,
double  value 
)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

void OBT::TiXmlElement::SetDoubleAttribute ( const char *  name,
double  value 
)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

Definition at line 707 of file OBTtinyxml.cpp.

References SetAttribute().

00708 {       
00709         char buf[256];
00710         #if defined(TIXML_SNPRINTF)             
00711                 TIXML_SNPRINTF( buf, sizeof(buf), "%f", val );
00712         #else
00713                 sprintf( buf, "%f", val );
00714         #endif
00715         SetAttribute( name, buf );
00716 }

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

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

Reimplemented from OBT::TiXmlNode.

Definition at line 1131 of file tiny/OBTtinyxml.h.

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

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

Reimplemented from OBT::TiXmlNode.

Definition at line 1130 of file tiny/OBTtinyxml.h.

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

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

Reimplemented from OBT::TiXmlNode.

Definition at line 1132 of file OBTtinyxml.h.

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

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

Reimplemented from OBT::TiXmlNode.

Definition at line 1131 of file OBTtinyxml.h.


Member Data Documentation


Generated on 1 Jan 2010 for OBT by  doxygen 1.6.1