Support Forum       G3D Web Page     
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< String, XMLAttributeTable
 
enum  Type {
  VALUE,
  TAG
}
 

Public Member Functions

 XML ()
 
 XML (const String &v)
 
 XML (const double &v)
 
 XML (float v)
 
 XML (int v)
 
 XML (Type tagType, const String &name, const AttributeTable &at, const Array< XML > &ch=Array< XML >())
 
 XML (Type tagType, const String &name, const Array< XML > &ch=Array< XML >())
 
 XML (TextInput &t)
 
const AttributeTableattributeTable () const
 
bool boolean () const
 Returns false if a TAG. More...
 
const Array< XML > & childArray () const
 
bool containsAttribute (const String &k) const
 
void deserialize (TextInput &t)
 
XML get (const String &k, const XML &defaultVal) const
 Note that the result is always copied, making this inefficient for return values that are not VALUEs. More...
 
void load (const String &filename)
 
const String name () const
 The name, if this is a TAG. More...
 
size_t numAttributes () const
 Attribute table size; zero for a TAG. More...
 
double number () const
 Parse as a number. More...
 
int numChildren () const
 Array size; zero for a VALUE. More...
 
 operator bool () const
 
 operator double () const
 
 operator float () const
 
 operator int () const
 
 operator String () const
 
const XMLoperator[] (int i) const
 Return child i. More...
 
const XMLoperator[] (const String &k) const
 Return the attribute with this name. More...
 
void parse (const String &s)
 
void save (const String &filename, bool collapseEmptyTags=false) const
 
void serialize (TextOutput &t, bool collapseEmptyTags=false) const
 
const Stringstring () const
 Returns "" if a TAG. More...
 
Type type () const
 
void unparse (String &s, bool collapseEmptyTags=false) const
 If collapseEmptyTags, writes tags with no children as a single tag. More...
 
const Stringvalue () 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 "--&gt;" e.g.,

  <?xml version="1.0" encoding="ISO-8859-1"?>
  <!DOCTYPE note SYSTEM "Note.dtd">
  <!-- a comment -->
See also
G3D::Any, http://www.grinninglizard.com/tinyxml/

<foo key0="value0" key1="value1">
  child0 ...
  <child1>...
 

Member Typedef Documentation

◆ AttributeTable

Member Enumeration Documentation

◆ Type

Enumerator
VALUE 
TAG 

Constructor & Destructor Documentation

◆ XML() [1/8]

G3D::XML::XML ( )
inline

◆ XML() [2/8]

G3D::XML::XML ( const String v)
inline

◆ XML() [3/8]

G3D::XML::XML ( const double &  v)
inline

◆ XML() [4/8]

G3D::XML::XML ( float  v)
inline

◆ XML() [5/8]

G3D::XML::XML ( int  v)
inline

◆ XML() [6/8]

G3D::XML::XML ( Type  tagType,
const String name,
const AttributeTable at,
const Array< XML > &  ch = Array<XML>() 
)
inline
Parameters
tagTypeMust be XML::TAG to dismbiguate from the string constructor

◆ XML() [7/8]

G3D::XML::XML ( Type  tagType,
const String name,
const Array< XML > &  ch = Array<XML>() 
)
inline
Parameters
tagTypeMust be XML::TAG to dismbiguate from the string constructor

◆ XML() [8/8]

G3D::XML::XML ( TextInput t)

Member Function Documentation

◆ attributeTable()

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

◆ boolean()

bool G3D::XML::boolean ( ) const

Returns false if a TAG.

Referenced by operator bool().

◆ childArray()

const Array<XML>& G3D::XML::childArray ( ) const
inline

◆ containsAttribute()

bool G3D::XML::containsAttribute ( const String k) const
inline

◆ deserialize()

void G3D::XML::deserialize ( TextInput t)

◆ get()

XML G3D::XML::get ( const String k,
const XML defaultVal 
) const
inline

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

◆ load()

void G3D::XML::load ( const String filename)

◆ name()

const String G3D::XML::name ( ) const
inline

The name, if this is a TAG.

◆ numAttributes()

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

Attribute table size; zero for a TAG.

◆ number()

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

◆ numChildren()

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

Array size; zero for a VALUE.

◆ operator bool()

G3D::XML::operator bool ( ) const
inline

◆ operator double()

G3D::XML::operator double ( ) const
inline

◆ operator float()

G3D::XML::operator float ( ) const
inline

◆ operator int()

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

◆ operator String()

G3D::XML::operator String ( ) const
inline

◆ operator[]() [1/2]

const XML& G3D::XML::operator[] ( int  i) const
inline

Return child i.

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

◆ operator[]() [2/2]

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

Return the attribute with this name.

◆ parse()

void G3D::XML::parse ( const String s)

◆ save()

void G3D::XML::save ( const String filename,
bool  collapseEmptyTags = false 
) const

◆ serialize()

void G3D::XML::serialize ( TextOutput t,
bool  collapseEmptyTags = false 
) const

◆ string()

const String& G3D::XML::string ( ) const
inline

Returns "" if a TAG.

◆ type()

Type G3D::XML::type ( ) const
inline

◆ unparse()

void G3D::XML::unparse ( String s,
bool  collapseEmptyTags = false 
) const

If collapseEmptyTags, writes tags with no children as a single tag.

For example: <name atr0="val0"></name> Is instead: <name atr0="val0"/>

◆ value()

const String& G3D::XML::value ( ) const
inline

documentation generated on Wed Nov 24 2021 08:02:02 using doxygen 1.8.15