xml::XML Class Reference
[XML Tools]

Application interface for XML document reading/writing.

This class can manage a very small subset of XML domain. Indeed, this is all TBT requires, to keep the code using it as simple as possible. More...

#include <xml.hh>

Inheritance diagram for xml::XML:

Inheritance graph
[legend]
List of all members.

Public Member Functions

virtual void parse (const std::string &filename)
 Parse an xml file.
void save ()
 Save the resulting xml file to the hard drive, replacing the file previously saved.
void setNodeAppend (bool enabled)
 Append node, instead of replacing the first, when using setData.
template<typename T>
getData (const std::string &node_name, int index=0) const
 Get a text value.
template<typename T>
getAttr (const std::string &node_name, const std::string &attr_name, int index=0) const
 Get an attribute value.
template<typename T>
void setData (const std::string &node_name, const T &value)
 Replace text of node node_name by value.
template<typename T>
void setAttr (const std::string &node_name, const std::string &attr_name, const T &value)
 Replace an attribute of the node node_name by value.
template<>
void setData (const std::string &node_name, const std::string &value)
template<>
void setData (const std::string &node_name, const int &value)
template<>
void setData (const std::string &node_name, const bool &value)
template<>
void setAttr (const std::string &node_name, const std::string &attr_name, const std::string &value)
template<>
void setAttr (const std::string &node_name, const std::string &attr_name, const int &value)
template<>
void setAttr (const std::string &node_name, const std::string &attr_name, const bool &value)

Protected Member Functions

virtual const char * getExpectedRoot () const =0
 Root node name we expect when loading the document.

Protected Attributes

XMLInternalxml_internal_
std::string filename_

Friends

std::ostream & operator<< (std::ostream &os, const XML &xml)
 Dump current xml data into ostream. Useful for debbugging.

Detailed Description

Application interface for XML document reading/writing.

This class can manage a very small subset of XML domain. Indeed, this is all TBT requires, to keep the code using it as simple as possible.

Always call parse before doing anything, not doing it will invoke strange things. Be prepared to catch XMLError, as it can be sent by approximatively all functions. Other xerces exceptions may be thrown, but consider it as a bug and report it instead of catching it.

Do not instanciate this class directly, use XML*, which have more knowledge about the document you access.

See also:
There are some examples of its usage in stechec/tools/xml_test directory.
Author:
victor
Date:
21/01/2006


Member Function Documentation

std::string xml::XML::getAttr ( const std::string &  node_name,
const std::string &  attr_name,
int  index = 0 
) const

Get an attribute value.

(ex:

<roll val="2" />
, return "2").
Parameters:
node_name The node to get value from. (from the exemple above, "roll").
attr_name The attribute name to get value from. (from the example above, "val").

std::string xml::XML::getData ( const std::string &  node_name,
int  index = 0 
) const

Get a text value.

(ex:

<roll>2</rool>
, return "2").
Parameters:
node_name The node to get text from. (from the exemple above, "roll").
Returns:
Return the value of the desired type. Currently, int, bool, and

void xml::XML::parse ( const std::string &  filename  )  [virtual]

Parse an xml file.

Parameters:
filename File to parse.
Exceptions:
XMLError Thrown on any kind of error.

Reimplemented in xml::XMLConfig, and xml::XMLFormation.

void xml::XML::save (  ) 

Save the resulting xml file to the hard drive, replacing the file previously saved.

Exceptions:
XMLError Thrown on any kind of error.

template<typename T>
void xml::XML::setAttr ( const std::string &  node_name,
const std::string &  attr_name,
const T &  value 
)

Replace an attribute of the node node_name by value.

It create a new attribute if node_name is not found.

template<typename T>
void xml::XML::setData ( const std::string &  node_name,
const T &  value 
)

Replace text of node node_name by value.

It creates a new node if node_name is not found.


The documentation for this class was generated from the following files:
Generated on Sat Jun 23 16:16:16 2007 for Stechec/TBT by  doxygen 1.4.7