TiXmlDeclaration Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlDeclaration:
TiXmlNode TiXmlBase

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

Private Attributes

TIXML_STRING version
TIXML_STRING encoding
TIXML_STRING standalone

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


Constructor & Destructor Documentation

TiXmlDeclaration::TiXmlDeclaration (  )  [inline]

Construct an empty declaration.

Definition at line 1260 of file tinyxml.h.

Referenced by Clone().

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

Constructor.

TiXmlDeclaration::TiXmlDeclaration ( const char *  _version,
const char *  _encoding,
const char *  _standalone 
)

Construct.

Definition at line 1364 of file tinyxml.cpp.

References encoding, standalone, and version.

01367         : TiXmlNode( TiXmlNode::DECLARATION )
01368 {
01369         version = _version;
01370         encoding = _encoding;
01371         standalone = _standalone;
01372 }

TiXmlDeclaration::TiXmlDeclaration ( const TiXmlDeclaration copy  ) 

Definition at line 1388 of file tinyxml.cpp.

References CopyTo().

01389         : TiXmlNode( TiXmlNode::DECLARATION )
01390 {
01391         copy.CopyTo( this );    
01392 }

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

Definition at line 1277 of file tinyxml.h.

01277 {}


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 1434 of file tinyxml.cpp.

References TiXmlVisitor::Visit().

01435 {
01436         return visitor->Visit( *this );
01437 }

TiXmlNode * TiXmlDeclaration::Clone (  )  const [virtual]

Creates a copy of this Declaration and returns it.

Implements TiXmlNode.

Definition at line 1440 of file tinyxml.cpp.

References CopyTo(), and TiXmlDeclaration().

01441 {       
01442         TiXmlDeclaration* clone = new TiXmlDeclaration();
01443 
01444         if ( !clone )
01445                 return 0;
01446 
01447         CopyTo( clone );
01448         return clone;
01449 }

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

Reimplemented from TiXmlNode.

Definition at line 1424 of file tinyxml.cpp.

References encoding, standalone, and version.

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

01425 {
01426         TiXmlNode::CopyTo( target );
01427 
01428         target->version = version;
01429         target->encoding = encoding;
01430         target->standalone = standalone;
01431 }

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

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

Definition at line 1282 of file tinyxml.h.

References encoding.

Referenced by TiXmlDocument::Parse().

01282 { return encoding.c_str (); }

void TiXmlDeclaration::operator= ( const TiXmlDeclaration copy  ) 

Reimplemented from TiXmlNode.

Definition at line 1395 of file tinyxml.cpp.

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

01396 {
01397         Clear();
01398         copy.CopyTo( this );
01399 }

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

Implements TiXmlBase.

Definition at line 1540 of file tinyxmlparser.cpp.

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

01541 {
01542         p = SkipWhiteSpace( p, _encoding );
01543         // Find the beginning, find the end, and look for
01544         // the stuff in-between.
01545         TiXmlDocument* document = GetDocument();
01546         if ( !p || !*p || !StringEqual( p, "<?xml", true, _encoding ) )
01547         {
01548                 if ( document ) document->SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding );
01549                 return 0;
01550         }
01551         if ( data )
01552         {
01553                 data->Stamp( p, _encoding );
01554                 location = data->Cursor();
01555         }
01556         p += 5;
01557 
01558         version = "";
01559         encoding = "";
01560         standalone = "";
01561 
01562         while ( p && *p )
01563         {
01564                 if ( *p == '>' )
01565                 {
01566                         ++p;
01567                         return p;
01568                 }
01569 
01570                 p = SkipWhiteSpace( p, _encoding );
01571                 if ( StringEqual( p, "version", true, _encoding ) )
01572                 {
01573                         TiXmlAttribute attrib;
01574                         p = attrib.Parse( p, data, _encoding );         
01575                         version = attrib.Value();
01576                 }
01577                 else if ( StringEqual( p, "encoding", true, _encoding ) )
01578                 {
01579                         TiXmlAttribute attrib;
01580                         p = attrib.Parse( p, data, _encoding );         
01581                         encoding = attrib.Value();
01582                 }
01583                 else if ( StringEqual( p, "standalone", true, _encoding ) )
01584                 {
01585                         TiXmlAttribute attrib;
01586                         p = attrib.Parse( p, data, _encoding );         
01587                         standalone = attrib.Value();
01588                 }
01589                 else
01590                 {
01591                         // Read over whatever it is.
01592                         while( p && *p && *p != '>' && !IsWhiteSpace( *p ) )
01593                                 ++p;
01594                 }
01595         }
01596         return 0;
01597 }

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

References Print().

01290                                                            {
01291                 Print( cfile, depth, 0 );
01292         }

void TiXmlDeclaration::Print ( FILE *  cfile,
int  depth,
TIXML_STRING *  str 
) const [virtual]

Definition at line 1402 of file tinyxml.cpp.

References encoding, standalone, and version.

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

01403 {
01404         if ( cfile ) fprintf( cfile, "<?xml " );
01405         if ( str )       (*str) += "<?xml ";
01406 
01407         if ( !version.empty() ) {
01408                 if ( cfile ) fprintf (cfile, "version=\"%s\" ", version.c_str ());
01409                 if ( str ) { (*str) += "version=\""; (*str) += version; (*str) += "\" "; }
01410         }
01411         if ( !encoding.empty() ) {
01412                 if ( cfile ) fprintf (cfile, "encoding=\"%s\" ", encoding.c_str ());
01413                 if ( str ) { (*str) += "encoding=\""; (*str) += encoding; (*str) += "\" "; }
01414         }
01415         if ( !standalone.empty() ) {
01416                 if ( cfile ) fprintf (cfile, "standalone=\"%s\" ", standalone.c_str ());
01417                 if ( str ) { (*str) += "standalone=\""; (*str) += standalone; (*str) += "\" "; }
01418         }
01419         if ( cfile ) fprintf( cfile, "?>" );
01420         if ( str )       (*str) += "?>";
01421 }

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

Is this a standalone document?

Definition at line 1284 of file tinyxml.h.

References standalone.

01284 { return standalone.c_str (); }

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

Implements TiXmlNode.

Definition at line 1517 of file tinyxmlparser.cpp.

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

01518 {
01519         while ( in->good() )
01520         {
01521                 int c = in->get();
01522                 if ( c <= 0 )
01523                 {
01524                         TiXmlDocument* document = GetDocument();
01525                         if ( document )
01526                                 document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
01527                         return;
01528                 }
01529                 (*tag) += (char) c;
01530 
01531                 if ( c == '>' )
01532                 {
01533                         // All is well.
01534                         return;
01535                 }
01536         }
01537 }

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

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

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

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

Definition at line 1280 of file tinyxml.h.

References version.

01280 { return version.c_str (); }


Member Data Documentation

TIXML_STRING TiXmlDeclaration::encoding [private]

Definition at line 1313 of file tinyxml.h.

Referenced by CopyTo(), Encoding(), Parse(), Print(), and TiXmlDeclaration().

TIXML_STRING TiXmlDeclaration::standalone [private]

Definition at line 1314 of file tinyxml.h.

Referenced by CopyTo(), Parse(), Print(), Standalone(), and TiXmlDeclaration().

TIXML_STRING TiXmlDeclaration::version [private]

Definition at line 1312 of file tinyxml.h.

Referenced by CopyTo(), Parse(), Print(), TiXmlDeclaration(), and Version().


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

Generated on 19 Jan 2018 for loon by  doxygen 1.6.1