Support Forum       Library Source       SourceForge Page       G3D Web Page     
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | List of all members
G3D::XML Class Reference

Easy loading and saving of XML and HTML files. More...

Public Types

typedef Table< std::string, XMLAttributeTable
 
enum  Type {
  VALUE,
  TAG
}
 

Public Member Functions

 XML ()
 
 XML (const std::string &v)
 
 XML (const double &v)
 
 XML (float v)
 
 XML (int v)
 
 XML (Type tagType, const std::string &name, const AttributeTable &at, const Array< XML > &ch=Array< XML >())
 
 XML (Type tagType, const std::string &name, const Array< XML > &ch=Array< XML >())
 
 XML (TextInput &t)
 
const AttributeTableattributeTable () const
 
bool boolean () const
 Returns false if a TAG.
 
const Array< XML > & childArray () const
 
bool containsAttribute (const std::string &k) const
 
void deserialize (TextInput &t)
 
XML get (const std::string &k, const XML &defaultVal) const
 Note that the result is always copied, making this inefficient for return values that are not VALUEs.
 
void load (const std::string &filename)
 
const std::string name () const
 The name, if this is a TAG.
 
size_t numAttributes () const
 Attribute table size; zero for a TAG.
 
double number () const
 Parse as a number.
 
int numChildren () const
 Array size; zero for a VALUE.
 
 operator bool () const
 
 operator double () const
 
 operator float () const
 
 operator int () const
 
 operator std::string () const
 
const XMLoperator[] (int i) const
 Return child i.
 
const XMLoperator[] (const std::string &k) const
 Return the attribute with this name.
 
void parse (const std::string &s)
 
void save (const std::string &filename) const
 
void serialize (TextOutput &t) const
 
const std::string & string () const
 Returns "" if a TAG.
 
Type type () const
 
void unparse (std::string &s) const
 

Detailed Description

Easy loading and saving of XML and HTML files.

The XML class is intended primarily for interchange with other programs. We recommend using G3D::Any to make your own human-readable formats because it is a more general syntax, the implementation is more efficient, and contains better error handling.

Every XML is either a VALUE, or a TAG that contains both a table of its XML attributes and an array of its children. Children are nested tags and the strings between the nested tags.

No validation is performed, and the XML must be completely legal. XML Entity references (e.g., the ampersand codes for greater than and less than) are not automatically converted.

Tags with names that begin with "!" or "?" are ignored. Comment tags must end with "&ndash;>" e.g.,

  <?xml version="1.0" encoding="ISO-8859-1"?>
  <!DOCTYPE note SYSTEM "Note.dtd">
See Also
G3D::Any, http://www.grinninglizard.com/tinyxml/
<foo key0="value0" key1="value1">
  child0 ...
  <child1>...</child1>
  child2 ...
</foo>

Member Typedef Documentation

Member Enumeration Documentation

Enumerator:
VALUE 
TAG 

Constructor & Destructor Documentation

G3D::XML::XML ( )
inline
G3D::XML::XML ( const std::string v)
inline
G3D::XML::XML ( const double &  v)
inline
G3D::XML::XML ( float  v)
inline
G3D::XML::XML ( int  v)
inline
G3D::XML::XML ( Type  tagType,
const std::string name,
const AttributeTable at,
const Array< XML > &  ch = Array<XML>() 
)
inline
Parameters
tagTypeMust be XML::TAG to dismbiguate from the string constructor
G3D::XML::XML ( Type  tagType,
const std::string name,
const Array< XML > &  ch = Array<XML>() 
)
inline
Parameters
tagTypeMust be XML::TAG to dismbiguate from the string constructor
G3D::XML::XML ( TextInput t)

Member Function Documentation

const AttributeTable& G3D::XML::attributeTable ( ) const
inline
bool G3D::XML::boolean ( ) const

Returns false if a TAG.

Referenced by operator bool().

const Array<XML>& G3D::XML::childArray ( ) const
inline
bool G3D::XML::containsAttribute ( const std::string k) const
inline
void G3D::XML::deserialize ( TextInput t)
XML G3D::XML::get ( const std::string k,
const XML defaultVal 
) const
inline

Note that the result is always copied, making this inefficient for return values that are not VALUEs.

void G3D::XML::load ( const std::string filename)
const std::string G3D::XML::name ( ) const
inline

The name, if this is a TAG.

size_t G3D::XML::numAttributes ( ) const
inline

Attribute table size; zero for a TAG.

double G3D::XML::number ( ) const

Parse as a number.

Returns nan() if a TAG or unparseable as a number.

Referenced by operator double(), operator float(), and operator int().

int G3D::XML::numChildren ( ) const
inline

Array size; zero for a VALUE.

G3D::XML::operator bool ( ) const
inline
G3D::XML::operator double ( ) const
inline
G3D::XML::operator float ( ) const
inline
G3D::XML::operator int ( ) const
inline
G3D::XML::operator std::string ( ) const
inline
const XML& G3D::XML::operator[] ( int  i) const
inline

Return child i.

Children are nested tags and the unquoted strings of characters between tags.

const XML& G3D::XML::operator[] ( const std::string k) const
inline

Return the attribute with this name.

void G3D::XML::parse ( const std::string s)
void G3D::XML::save ( const std::string filename) const
void G3D::XML::serialize ( TextOutput t) const
const std::string& G3D::XML::string ( ) const
inline

Returns "" if a TAG.

Type G3D::XML::type ( ) const
inline
void G3D::XML::unparse ( std::string s) const

documentation generated on Sat Jan 12 2013 22:49:57 using doxygen 1.8.2