- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Exponent::IO::CXMLDocument Class Reference

List of all members.

## Detailed Description

Represents an xml document tree.

XML is at its basic level a tree of nodes. We follow this paradigm. An XML document will be written or read from a root node
that is the root of the tree. Each node may have n children who may in turn have n children.
Each element of the tree has a specific number (>= 0) of attributes
All attributes, children and names etc are represented by strings, but there are various ways in the API of converting between
strings and other objects, values etc
Here is an example of how to write a file

     // Can i just say, yes this entire example is about the tv show
     // The shield... possible the finest show ever made :)
     // First create the node that you are gonna fill
     CXMLNode *root = new CXMLNode("root", NULL);

     // Now add some attributes and children to it
     CXMLNode *strikeTream = new CXMLNode("strike_team", root);
     strikeTeam->addAttribute("number_of_members", "4");

     // Now add children
     CXMLNode *vic   = new CXMLNode("vic",   strikeTeam);
     CXMLNode *lemm  = new CXMLNode("lemm",  strikeTeam);
     CXMLNode *ronny = new CXMLNode("ronny", strikeTeam);
     CXMLNode *shane = new CXMLNode("shane", strikeTeam);

     // Set some attributes
     vic->addAttribute("description",  "hard ass");
     lemm->addAttribute("description", "The good guy");
     ronny->addAttribute("description", "Who?");
     shane->addAttribute("description", "Scumm bag");

     // Now add them to the strike team node
     strikeTeam->addChildNode(vic);
     strikeTeam->addChildNode(lemm);
     strikeTeam->addChildNode(ronny);
     strikeTeam->addChildNode(shane);

     // Add to the root -> notice that this reference counts all the objects, we can just ignore those pointers now...
     root->addChildNode(strikeTeam);

     // Now set and write
     CXMLDocument document;
     document.setRootNode(root);
     if (!document.writeFile("Path/To/MyFile.xml"))
     {
         cout << "Failed to write document" << endl;
     }

Here is an example of how to read a file:

     // We are going to read the document, then we have the node available to process
     CXMLDocument document;
     if (!document.readFile("Path/To/MyFile.xml"))
     {
         cout << "Failed to read document" << endl;
     }
     else
     {
            // Store the root node
            const CXMLNode *root = document.getRootNode();

            // Check its valid
            if (root == NULL) return;

          // Now we can process with the node
          ...
     }

See also:
  CXMLAttribute

  CXMLNode

Date:
  17/08/2005

Author:
  Paul Chana

Version:
  1.0.0 Initial version

Note:
  This is a very basic implementation of XML reading and writing.
  It is intended as an opening in to the world of XML to be updated at a later date
  Currently not supported are multiline comments nor seperate DTD nor unicode
  Comliance with XML documents written by other sources may be a bit buggy, please make sure you check your code ;)

  All contents of this source code are copyright 2005 Exp Digital Uk.
  This source file is covered by the licence conditions of the Infinity API. You should have recieved a copy
  with the source code. If you didnt, please refer to http://www.expdigital.co.uk All content is the Intellectual property of Exp Digital Uk.
  Certain sections of this code may come from other sources. They are credited where applicable.
  If you have comments, suggestions or bug reports please visit http://support.expdigital.co.uk

Id
  CXMLDocument.hpp,v 1.5 2007/02/08 21:06:44 paul Exp

Definition at line 105 of file CXMLDocument.hpp.

## Public Member Functions

- CXMLDocument ()
- CXMLNode * getMutableRootNode ()
- const CXMLNode * getRootNode () const
- bool readFile (const CSystemString &filename)
- void setRootNode (CXMLNode *root)
- bool writeFile (const CSystemString &filename)
- virtual ~CXMLDocument ()

## Protected Member Functions

- void indentOutput (CTextStream &stream)
- void outputDTD (CTextStream &stream)
- void outputNode (CXMLNode *node, CTextStream &stream)
- bool processString (CString &string, CTextStream &stream)
- bool readDTD (CTextStream &stream)
- void replaceEscapeCharacters (CString &string)
- void replaceIllegalCharacters (CString &string)

## Protected Attributes

- long m_indentLevel
- CXMLNode * m_readNode
- CXMLNode * m_rootNode

## Constructor & Destructor Documentation

Exponent::IO::CXMLDocument::CXMLDocument | ( |  | ) |

Construction

virtual Exponent::IO::CXMLDocument::~CXMLDocument | ( |  | ) | `[virtual]`

Destruction

## Member Function Documentation

CXMLNode* Exponent::IO::CXMLDocument::getMutableRootNode | ( |  | ) |

Get the root node

Return values:

  | const | CXMLNode* The root node, possible NULL

const CXMLNode* Exponent::IO::CXMLDocument::getRootNode | ( |  | ) | const

Get the root node

Return values:

  | const | CXMLNode* The root node, possible NULL

void Exponent::IO::CXMLDocument::indentOutput | ( | CTextStream & | stream | ) | `[protected]`

Indent the output

Parameters:

  | stream | The text stream to indent

void Exponent::IO::CXMLDocument::outputDTD | ( | CTextStream & | stream | ) | `[protected]`

Output the DTD header - <?xml version=\"1.0\" encoding=\"UTF-8\" \?>

Parameters:

  | stream | The textt stream to write to

void Exponent::IO::CXMLDocument::outputNode | ( | CXMLNode * | node,
|  | CTextStream & | stream |
| ) |  |  | `[protected]`

Output a node

Parameters:

  | node | The xml node to output
  | stream | The text stream to use

bool Exponent::IO::CXMLDocument::processString | ( | CString & | string,
|  | CTextStream & | stream |
| ) |  |  | `[protected]`

Process a given string

Parameters:

  | string | The string to read
  | stream | The text stream to read from as necessary

Return values:

  | bool | True if read properly, false otherwise

bool Exponent::IO::CXMLDocument::readDTD | ( | CTextStream & | stream | ) | `[protected]`

Read the DTD

Parameters:

  | stream | The textt stream to write from

Return values:

  | bool | True if read properly, false otherwise

bool Exponent::IO::CXMLDocument::readFile | ( | const CSystemString & | filename | ) |

Read an entire file and create the XML object tree

Parameters:

  | filename | The name of the file

Return values:

  | bool | True if read properly, false otherwise

void Exponent::IO::CXMLDocument::replaceEscapeCharacters | ( | CString & | string | ) | `[protected]`

Replace input string character that are legal with illegal versions of them

Parameters:

  | string | The string to check and replace

void Exponent::IO::CXMLDocument::replaceIllegalCharacters | ( | CString & | string | ) | `[protected]`

Replace output string characters that are illegal with legal versions of them

Parameters:

  | string | The string to check and replace

void Exponent::IO::CXMLDocument::setRootNode | ( | CXMLNode * | root | ) |

Set the root node

Parameters:

  | root | The root node

bool Exponent::IO::CXMLDocument::writeFile | ( | const CSystemString & | filename | ) |

Write the tree as stored in root node to disk file

Parameters:

  | filename | The name of the file to write to

Return values:

  | bool | True if written properly, false otherwise

## Member Data Documentation

long Exponent::IO::CXMLDocument::m_indentLevel`[protected]`

How many levels of indent are we at

Definition at line 223 of file CXMLDocument.hpp.

CXMLNode* Exponent::IO::CXMLDocument::m_readNode`[protected]`

Traversal node

Definition at line 221 of file CXMLDocument.hpp.

CXMLNode* Exponent::IO::CXMLDocument::m_rootNode`[protected]`

Root node

Definition at line 222 of file CXMLDocument.hpp.