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; }
// 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 ... }
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
Definition at line 105 of file CXMLDocument.hpp.
Exponent::IO::CXMLDocument::CXMLDocument | ( | ) |
Construction
virtual Exponent::IO::CXMLDocument::~CXMLDocument | ( | ) | [virtual] |
Destruction
CXMLNode* Exponent::IO::CXMLDocument::getMutableRootNode | ( | ) |
Get the root node
const | CXMLNode* The root node, possible NULL |
const CXMLNode* Exponent::IO::CXMLDocument::getRootNode | ( | ) | const |
Get the root node
const | CXMLNode* The root node, possible NULL |
void Exponent::IO::CXMLDocument::indentOutput | ( | CTextStream & | stream | ) | [protected] |
Indent the output
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\" \?>
stream | The textt stream to write to |
void Exponent::IO::CXMLDocument::outputNode | ( | CXMLNode * | node, | |
CTextStream & | stream | |||
) | [protected] |
Output a node
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
string | The string to read | |
stream | The text stream to read from as necessary |
bool | True if read properly, false otherwise |
bool Exponent::IO::CXMLDocument::readDTD | ( | CTextStream & | stream | ) | [protected] |
Read the DTD
stream | The textt stream to write from |
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
filename | The name of the file |
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
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
string | The string to check and replace |
void Exponent::IO::CXMLDocument::setRootNode | ( | CXMLNode * | root | ) |
Set the root node
root | The root node |
bool Exponent::IO::CXMLDocument::writeFile | ( | const CSystemString & | filename | ) |
Write the tree as stored in root node to disk file
filename | The name of the file to write to |
bool | True if written properly, false otherwise |
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.