Public Member Functions | Protected Member Functions

TiXmlDeclaration Class Reference

#include <tinyxml.h>

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

List of all members.

Public Member Functions

 TiXmlDeclaration ()
 Construct an empty declaration.
 TiXmlDeclaration (const std::string &_version, const std::string &_encoding, const std::string &_standalone)
 Constructor.
 TiXmlDeclaration (const char *_version, const char *_encoding, const char *_standalone)
 Construct.
 TiXmlDeclaration (const TiXmlDeclaration &copy)
void operator= (const TiXmlDeclaration &copy)
virtual ~TiXmlDeclaration ()
const char * Version () const
 Version. Will return an empty string if none was found.
const char * Encoding () const
 Encoding. Will return an empty string if none was found.
const char * Standalone () const
 Is this a standalone document?
virtual TiXmlNodeClone () const
 Creates a copy of this Declaration and returns it.
virtual void Print (FILE *cfile, int depth, TiXmlString *str) const
virtual void Print (FILE *cfile, int depth) const
virtual const char * Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlDeclarationToDeclaration () const
 Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlDeclarationToDeclaration ()
 Cast to a more defined type. Will return null not of the requested type.
virtual bool Accept (TiXmlVisitor *visitor) const

Protected Member Functions

void CopyTo (TiXmlDeclaration *target) const
virtual void StreamIn (std::istream *in, TiXmlString *tag)

Detailed Description

In correct XML the declaration is the first entry in the file.

		<?xml version="1.0" standalone="yes"?>
	

TinyXml will happily read or write files without a declaration, however. There are 3 possible attributes to the declaration: version, encoding, and standalone.

Note: In this version of the code, the attributes are handled as special cases, not generic attributes, simply because there can only be at most 3 and they are always the same.

Definition at line 1283 of file tinyxml.h.


Constructor & Destructor Documentation

TiXmlDeclaration::TiXmlDeclaration (  ) [inline]

Construct an empty declaration.

Definition at line 1287 of file tinyxml.h.

Referenced by Clone().

TiXmlDeclaration::TiXmlDeclaration ( const std::string &  _version,
const std::string &  _encoding,
const std::string &  _standalone 
)

Constructor.

Definition at line 1345 of file tinyxml.cpp.

        : TiXmlNode( TiXmlNode::TINYXML_DECLARATION )
{
        version = _version;
        encoding = _encoding;
        standalone = _standalone;
}
TiXmlDeclaration::TiXmlDeclaration ( const char *  _version,
const char *  _encoding,
const char *  _standalone 
)

Construct.

Definition at line 1333 of file tinyxml.cpp.

        : TiXmlNode( TiXmlNode::TINYXML_DECLARATION )
{
        version = _version;
        encoding = _encoding;
        standalone = _standalone;
}
TiXmlDeclaration::TiXmlDeclaration ( const TiXmlDeclaration copy )

Definition at line 1357 of file tinyxml.cpp.

References CopyTo().

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

Definition at line 1304 of file tinyxml.h.

{}

Member Function Documentation

bool TiXmlDeclaration::Accept ( TiXmlVisitor visitor ) const [virtual]

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

Implements TiXmlNode.

Definition at line 1403 of file tinyxml.cpp.

References TiXmlVisitor::Visit().

{
        return visitor->Visit( *this );
}
TiXmlNode * TiXmlDeclaration::Clone (  ) const [virtual]

Creates a copy of this Declaration and returns it.

Implements TiXmlNode.

Definition at line 1409 of file tinyxml.cpp.

References CopyTo(), and TiXmlDeclaration().

{       
        TiXmlDeclaration* clone = new TiXmlDeclaration();

        if ( !clone )
                return 0;

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

Definition at line 1393 of file tinyxml.cpp.

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

{
        TiXmlNode::CopyTo( target );

        target->version = version;
        target->encoding = encoding;
        target->standalone = standalone;
}
const char* TiXmlDeclaration::Encoding (  ) const [inline]

Encoding. Will return an empty string if none was found.

Definition at line 1309 of file tinyxml.h.

Referenced by TiXmlDocument::Parse().

{ return encoding.c_str (); }
void TiXmlDeclaration::operator= ( const TiXmlDeclaration copy )

Definition at line 1364 of file tinyxml.cpp.

References TiXmlNode::Clear(), and CopyTo().

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

Implements TiXmlBase.

Definition at line 1569 of file tinyxmlparser.cpp.

References TiXmlParsingData::Cursor(), TiXmlNode::GetDocument(), TiXmlBase::IsWhiteSpace(), TiXmlBase::location, TiXmlAttribute::Parse(), TiXmlDocument::SetError(), TiXmlBase::SkipWhiteSpace(), TiXmlParsingData::Stamp(), TiXmlBase::StringEqual(), TiXmlBase::TIXML_ERROR_PARSING_DECLARATION, and TiXmlAttribute::Value().

{
        p = SkipWhiteSpace( p, _encoding );
        // Find the beginning, find the end, and look for
        // the stuff in-between.
        TiXmlDocument* document = GetDocument();
        if ( !p || !*p || !StringEqual( p, "<?xml", true, _encoding ) )
        {
                if ( document ) document->SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding );
                return 0;
        }
        if ( data )
        {
                data->Stamp( p, _encoding );
                location = data->Cursor();
        }
        p += 5;

        version = "";
        encoding = "";
        standalone = "";

        while ( p && *p )
        {
                if ( *p == '>' )
                {
                        ++p;
                        return p;
                }

                p = SkipWhiteSpace( p, _encoding );
                if ( StringEqual( p, "version", true, _encoding ) )
                {
                        TiXmlAttribute attrib;
                        p = attrib.Parse( p, data, _encoding );         
                        version = attrib.Value();
                }
                else if ( StringEqual( p, "encoding", true, _encoding ) )
                {
                        TiXmlAttribute attrib;
                        p = attrib.Parse( p, data, _encoding );         
                        encoding = attrib.Value();
                }
                else if ( StringEqual( p, "standalone", true, _encoding ) )
                {
                        TiXmlAttribute attrib;
                        p = attrib.Parse( p, data, _encoding );         
                        standalone = attrib.Value();
                }
                else
                {
                        // Read over whatever it is.
                        while( p && *p && *p != '>' && !IsWhiteSpace( *p ) )
                                ++p;
                }
        }
        return 0;
}
void TiXmlDeclaration::Print ( FILE *  cfile,
int  depth,
TiXmlString *  str 
) const [virtual]

Definition at line 1371 of file tinyxml.cpp.

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

{
        if ( cfile ) fprintf( cfile, "<?xml " );
        if ( str )       (*str) += "<?xml ";

        if ( !version.empty() ) {
                if ( cfile ) fprintf (cfile, "version=\"%s\" ", version.c_str ());
                if ( str ) { (*str) += "version=\""; (*str) += version; (*str) += "\" "; }
        }
        if ( !encoding.empty() ) {
                if ( cfile ) fprintf (cfile, "encoding=\"%s\" ", encoding.c_str ());
                if ( str ) { (*str) += "encoding=\""; (*str) += encoding; (*str) += "\" "; }
        }
        if ( !standalone.empty() ) {
                if ( cfile ) fprintf (cfile, "standalone=\"%s\" ", standalone.c_str ());
                if ( str ) { (*str) += "standalone=\""; (*str) += standalone; (*str) += "\" "; }
        }
        if ( cfile ) fprintf( cfile, "?>" );
        if ( str )       (*str) += "?>";
}
virtual void TiXmlDeclaration::Print ( FILE *  cfile,
int  depth 
) const [inline, 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.h.

References Print().

                                                           {
                Print( cfile, depth, 0 );
        }
const char* TiXmlDeclaration::Standalone (  ) const [inline]

Is this a standalone document?

Definition at line 1311 of file tinyxml.h.

{ return standalone.c_str (); }
void TiXmlDeclaration::StreamIn ( std::istream *  in,
TiXmlString *  tag 
) [protected, virtual]

Implements TiXmlNode.

Definition at line 1546 of file tinyxmlparser.cpp.

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

{
        while ( in->good() )
        {
                int c = in->get();
                if ( c <= 0 )
                {
                        TiXmlDocument* document = GetDocument();
                        if ( document )
                                document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
                        return;
                }
                (*tag) += (char) c;

                if ( c == '>' )
                {
                        // All is well.
                        return;
                }
        }
}
virtual const TiXmlDeclaration* TiXmlDeclaration::ToDeclaration (  ) const [inline, virtual]

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

Reimplemented from TiXmlNode.

Definition at line 1323 of file tinyxml.h.

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

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

Reimplemented from TiXmlNode.

Definition at line 1324 of file tinyxml.h.

const char* TiXmlDeclaration::Version (  ) const [inline]

Version. Will return an empty string if none was found.

Definition at line 1307 of file tinyxml.h.

{ return version.c_str (); }

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