TiXmlText Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlText:
TiXmlNode TiXmlBase

List of all members.

Public Member Functions

 TiXmlText (const char *initValue)
virtual ~TiXmlText ()
 TiXmlText (const std::string &initValue)
 Constructor.
 TiXmlText (const TiXmlText &copy)
void operator= (const TiXmlText &base)
virtual void Print (FILE *cfile, int depth) const
bool CDATA () const
 Queries whether this represents text using a CDATA section.
void SetCDATA (bool _cdata)
 Turns on or off a CDATA representation of text.
virtual const char * Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlTextToText () const
 Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlTextToText ()
 Cast to a more defined type. Will return null not of the requested type.
virtual bool Accept (TiXmlVisitor *content) const

Protected Member Functions

virtual TiXmlNodeClone () const
 [internal use] Creates a new Element and returns it.
void CopyTo (TiXmlText *target) const
bool Blank () const
virtual void StreamIn (std::istream *in, TIXML_STRING *tag)

Private Attributes

bool cdata

Friends

class TiXmlElement

Detailed Description

XML text. A text node can have 2 ways to output the next. "normal" output and CDATA. It will default to the mode it was parsed from the XML file and you generally want to leave it alone, but you can change the output mode with SetCDATA() and query it with CDATA().

Definition at line 1183 of file tinyxml.h.


Constructor & Destructor Documentation

TiXmlText::TiXmlText ( const char *  initValue  )  [inline]

Constructor for text element. By default, it is treated as normal, encoded text. If you want it be output as a CDATA text element, set the parameter _cdata to 'true'

Definition at line 1191 of file tinyxml.h.

References cdata, and TiXmlNode::SetValue().

Referenced by Clone().

01191                                             : TiXmlNode (TiXmlNode::TEXT)
01192         {
01193                 SetValue( initValue );
01194                 cdata = false;
01195         }

virtual TiXmlText::~TiXmlText (  )  [inline, virtual]

Definition at line 1196 of file tinyxml.h.

01196 {}

TiXmlText::TiXmlText ( const std::string &  initValue  )  [inline]

Constructor.

Definition at line 1200 of file tinyxml.h.

References cdata, and TiXmlNode::SetValue().

01200                                                 : TiXmlNode (TiXmlNode::TEXT)
01201         {
01202                 SetValue( initValue );
01203                 cdata = false;
01204         }

TiXmlText::TiXmlText ( const TiXmlText copy  )  [inline]

Definition at line 1207 of file tinyxml.h.

References CopyTo().

01207 : TiXmlNode( TiXmlNode::TEXT )  { copy.CopyTo( this ); }


Member Function Documentation

bool TiXmlText::Accept ( TiXmlVisitor content  )  const [virtual]

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

Implements TiXmlNode.

Definition at line 1345 of file tinyxml.cpp.

References TiXmlVisitor::Visit().

01346 {
01347         return visitor->Visit( *this );
01348 }

bool TiXmlText::Blank (  )  const [protected]

Definition at line 1599 of file tinyxmlparser.cpp.

References TiXmlBase::IsWhiteSpace(), and TiXmlNode::value.

Referenced by TiXmlElement::ReadValue().

01600 {
01601         for ( unsigned i=0; i<value.length(); i++ )
01602                 if ( !IsWhiteSpace( value[i] ) )
01603                         return false;
01604         return true;
01605 }

bool TiXmlText::CDATA (  )  const [inline]

Queries whether this represents text using a CDATA section.

Definition at line 1214 of file tinyxml.h.

References cdata.

Referenced by TiXmlPrinter::Visit(), and TiXmlPrinter::VisitEnter().

01214 { return cdata; }

TiXmlNode * TiXmlText::Clone (  )  const [protected, virtual]

[internal use] Creates a new Element and returns it.

Implements TiXmlNode.

Definition at line 1351 of file tinyxml.cpp.

References CopyTo(), and TiXmlText().

01352 {       
01353         TiXmlText* clone = 0;
01354         clone = new TiXmlText( "" );
01355 
01356         if ( !clone )
01357                 return 0;
01358 
01359         CopyTo( clone );
01360         return clone;
01361 }

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

Reimplemented from TiXmlNode.

Definition at line 1338 of file tinyxml.cpp.

References cdata.

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

01339 {
01340         TiXmlNode::CopyTo( target );
01341         target->cdata = cdata;
01342 }

void TiXmlText::operator= ( const TiXmlText base  )  [inline]

Reimplemented from TiXmlNode.

Definition at line 1208 of file tinyxml.h.

References CopyTo().

01208 { base.CopyTo( this ); }

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

Implements TiXmlBase.

Definition at line 1466 of file tinyxmlparser.cpp.

References cdata, TiXmlParsingData::Cursor(), TiXmlNode::GetDocument(), TiXmlBase::location, TiXmlBase::ReadText(), TiXmlDocument::SetError(), TiXmlParsingData::Stamp(), TiXmlBase::StringEqual(), TiXmlBase::TIXML_ERROR_PARSING_CDATA, TIXML_STRING, and TiXmlNode::value.

Referenced by TiXmlElement::ReadValue().

01467 {
01468         value = "";
01469         TiXmlDocument* document = GetDocument();
01470 
01471         if ( data )
01472         {
01473                 data->Stamp( p, encoding );
01474                 location = data->Cursor();
01475         }
01476 
01477         const char* const startTag = "<![CDATA[";
01478         const char* const endTag   = "]]>";
01479 
01480         if ( cdata || StringEqual( p, startTag, false, encoding ) )
01481         {
01482                 cdata = true;
01483 
01484                 if ( !StringEqual( p, startTag, false, encoding ) )
01485                 {
01486                         document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding );
01487                         return 0;
01488                 }
01489                 p += strlen( startTag );
01490 
01491                 // Keep all the white space, ignore the encoding, etc.
01492                 while (    p && *p
01493                                 && !StringEqual( p, endTag, false, encoding )
01494                           )
01495                 {
01496                         value += *p;
01497                         ++p;
01498                 }
01499 
01500                 TIXML_STRING dummy; 
01501                 p = ReadText( p, &dummy, false, endTag, false, encoding );
01502                 return p;
01503         }
01504         else
01505         {
01506                 bool ignoreWhite = true;
01507 
01508                 const char* end = "<";
01509                 p = ReadText( p, &value, ignoreWhite, end, false, encoding );
01510                 if ( p )
01511                         return p-1;     // don't truncate the '<'
01512                 return 0;
01513         }
01514 }

void TiXmlText::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 TiXmlBase.

Definition at line 1317 of file tinyxml.cpp.

References cdata, TiXmlBase::PutString(), TIXML_STRING, and TiXmlNode::value.

01318 {
01319         assert( cfile );
01320         if ( cdata )
01321         {
01322                 int i;
01323                 fprintf( cfile, "\n" );
01324                 for ( i=0; i<depth; i++ ) {
01325                         fprintf( cfile, "    " );
01326                 }
01327                 fprintf( cfile, "<![CDATA[%s]]>\n", value.c_str() );    // unformatted output
01328         }
01329         else
01330         {
01331                 TIXML_STRING buffer;
01332                 PutString( value, &buffer );
01333                 fprintf( cfile, "%s", buffer.c_str() );
01334         }
01335 }

void TiXmlText::SetCDATA ( bool  _cdata  )  [inline]

Turns on or off a CDATA representation of text.

Definition at line 1216 of file tinyxml.h.

References cdata.

Referenced by TiXmlNode::Identify().

01216 { cdata = _cdata; }

void TiXmlText::StreamIn ( std::istream *  in,
TIXML_STRING *  tag 
) [protected, virtual]

Implements TiXmlNode.

Definition at line 1435 of file tinyxmlparser.cpp.

References cdata, TiXmlNode::GetDocument(), len, TiXmlDocument::SetError(), TIXML_ENCODING_UNKNOWN, and TiXmlBase::TIXML_ERROR_EMBEDDED_NULL.

Referenced by TiXmlElement::StreamIn().

01436 {
01437         while ( in->good() )
01438         {
01439                 int c = in->peek();     
01440                 if ( !cdata && (c == '<' ) ) 
01441                 {
01442                         return;
01443                 }
01444                 if ( c <= 0 )
01445                 {
01446                         TiXmlDocument* document = GetDocument();
01447                         if ( document )
01448                                 document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
01449                         return;
01450                 }
01451 
01452                 (*tag) += (char) c;
01453                 in->get();      // "commits" the peek made above
01454 
01455                 if ( cdata && c == '>' && tag->size() >= 3 ) {
01456                         size_t len = tag->size();
01457                         if ( (*tag)[len-2] == ']' && (*tag)[len-3] == ']' ) {
01458                                 // terminator of cdata.
01459                                 return;
01460                         }
01461                 }    
01462         }
01463 }

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

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

Reimplemented from TiXmlNode.

Definition at line 1221 of file tinyxml.h.

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

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

Reimplemented from TiXmlNode.

Definition at line 1220 of file tinyxml.h.


Friends And Related Function Documentation

friend class TiXmlElement [friend]

Reimplemented from TiXmlNode.

Definition at line 1185 of file tinyxml.h.


Member Data Documentation

bool TiXmlText::cdata [private]

Definition at line 1239 of file tinyxml.h.

Referenced by CDATA(), CopyTo(), Parse(), Print(), SetCDATA(), StreamIn(), and TiXmlText().


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

Generated on 16 Apr 2018 for loon by  doxygen 1.6.1