Public Member Functions | Protected Member Functions | Friends

TiXmlText Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlText:
Inheritance graph
[legend]
Collaboration diagram for TiXmlText:
Collaboration graph
[legend]

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, TiXmlString *tag)

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 1210 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 1218 of file tinyxml.h.

References TiXmlNode::SetValue().

Referenced by Clone().

                                            : TiXmlNode (TiXmlNode::TINYXML_TEXT)
        {
                SetValue( initValue );
                cdata = false;
        }
virtual TiXmlText::~TiXmlText (  ) [inline, virtual]

Definition at line 1223 of file tinyxml.h.

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

Constructor.

Definition at line 1227 of file tinyxml.h.

References TiXmlNode::SetValue().

                                                : TiXmlNode (TiXmlNode::TINYXML_TEXT)
        {
                SetValue( initValue );
                cdata = false;
        }
TiXmlText::TiXmlText ( const TiXmlText copy ) [inline]

Definition at line 1234 of file tinyxml.h.

References CopyTo().

: TiXmlNode( TiXmlNode::TINYXML_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 1314 of file tinyxml.cpp.

References TiXmlVisitor::Visit().

{
        return visitor->Visit( *this );
}
bool TiXmlText::Blank (  ) const [protected]

Definition at line 1628 of file tinyxmlparser.cpp.

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

Referenced by TiXmlElement::ReadValue().

{
        for ( unsigned i=0; i<value.length(); i++ )
                if ( !IsWhiteSpace( value[i] ) )
                        return false;
        return true;
}
bool TiXmlText::CDATA (  ) const [inline]

Queries whether this represents text using a CDATA section.

Definition at line 1241 of file tinyxml.h.

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

{ return cdata; }
TiXmlNode * TiXmlText::Clone (  ) const [protected, virtual]

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

Implements TiXmlNode.

Definition at line 1320 of file tinyxml.cpp.

References CopyTo(), and TiXmlText().

{       
        TiXmlText* clone = 0;
        clone = new TiXmlText( "" );

        if ( !clone )
                return 0;

        CopyTo( clone );
        return clone;
}
void TiXmlText::CopyTo ( TiXmlText target ) const [protected]

Definition at line 1307 of file tinyxml.cpp.

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

{
        TiXmlNode::CopyTo( target );
        target->cdata = cdata;
}
void TiXmlText::operator= ( const TiXmlText base ) [inline]

Definition at line 1235 of file tinyxml.h.

References CopyTo().

{ base.CopyTo( this ); }
const char * TiXmlText::Parse ( const char *  p,
TiXmlParsingData data,
TiXmlEncoding  encoding 
) [virtual]

Implements TiXmlBase.

Definition at line 1495 of file tinyxmlparser.cpp.

References 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().

{
        value = "";
        TiXmlDocument* document = GetDocument();

        if ( data )
        {
                data->Stamp( p, encoding );
                location = data->Cursor();
        }

        const char* const startTag = "<![CDATA[";
        const char* const endTag   = "]]>";

        if ( cdata || StringEqual( p, startTag, false, encoding ) )
        {
                cdata = true;

                if ( !StringEqual( p, startTag, false, encoding ) )
                {
                        document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding );
                        return 0;
                }
                p += strlen( startTag );

                // Keep all the white space, ignore the encoding, etc.
                while (    p && *p
                                && !StringEqual( p, endTag, false, encoding )
                          )
                {
                        value += *p;
                        ++p;
                }

                TIXML_STRING dummy; 
                p = ReadText( p, &dummy, false, endTag, false, encoding );
                return p;
        }
        else
        {
                bool ignoreWhite = true;

                const char* end = "<";
                p = ReadText( p, &value, ignoreWhite, end, false, encoding );
                if ( p )
                        return p-1;     // don't truncate the '<'
                return 0;
        }
}
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 1286 of file tinyxml.cpp.

References TiXmlBase::EncodeString(), TIXML_STRING, and TiXmlNode::value.

{
        assert( cfile );
        if ( cdata )
        {
                int i;
                fprintf( cfile, "\n" );
                for ( i=0; i<depth; i++ ) {
                        fprintf( cfile, "    " );
                }
                fprintf( cfile, "<![CDATA[%s]]>\n", value.c_str() );    // unformatted output
        }
        else
        {
                TIXML_STRING buffer;
                EncodeString( value, &buffer );
                fprintf( cfile, "%s", buffer.c_str() );
        }
}
void TiXmlText::SetCDATA ( bool  _cdata ) [inline]

Turns on or off a CDATA representation of text.

Definition at line 1243 of file tinyxml.h.

Referenced by TiXmlNode::Identify().

{ cdata = _cdata; }
void TiXmlText::StreamIn ( std::istream *  in,
TiXmlString *  tag 
) [protected, virtual]

Implements TiXmlNode.

Definition at line 1464 of file tinyxmlparser.cpp.

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

Referenced by TiXmlElement::StreamIn().

{
        while ( in->good() )
        {
                int c = in->peek();     
                if ( !cdata && (c == '<' ) ) 
                {
                        return;
                }
                if ( c <= 0 )
                {
                        TiXmlDocument* document = GetDocument();
                        if ( document )
                                document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
                        return;
                }

                (*tag) += (char) c;
                in->get();      // "commits" the peek made above

                if ( cdata && c == '>' && tag->size() >= 3 ) {
                        size_t len = tag->size();
                        if ( (*tag)[len-2] == ']' && (*tag)[len-3] == ']' ) {
                                // terminator of cdata.
                                return;
                        }
                }    
        }
}
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 1247 of file tinyxml.h.

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 1248 of file tinyxml.h.


Friends And Related Function Documentation

friend class TiXmlElement [friend]

Reimplemented from TiXmlNode.

Definition at line 1212 of file tinyxml.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines