VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
VICI::cfi::Xml Class Reference

A C++ wrapper for libxml2. More...

#include <vici/xml.h>

Inheritance diagram for VICI::cfi::Xml:
VICI::cfi::XINI VICI::EbnfXml VICI::gth::ScriptXML

Public Member Functions

virtual ~Xml ()
 Destructor.
 
void setDtd (csr name, const Path &dtd)
 Set DTD identifier to dtd, which is just the dtd file name. More...
 
void setDtd (csr name, csr ident, csr url)
 Set DTD identifier. More...
 
void getDtdIdentifiers (csr dtdName, std::string &publicId, std::string &systemId)
 Get the public identifier for the DTD. More...
 
void setCompression (int rate)
 Set the compression rate for saving the document. More...
 
void save ()
 Save the document.
 
void save (const Path &fname)
 Save the document to a new file. More...
 
void pack (XmlBuffer &)
 Save the document into a buffer.
 
bool dirty ()
 Check if the document has been modified. More...
 
void setDirty (bool dt)
 Access to dirty flag if we change document outside of this interface. More...
 
bool safeToSave ()
 Check if can save without clobbering other input. More...
 
void reload ()
 Reload the XML file.
 

Protected Member Functions

void createXPathContext ()
 Call this whenever mDoc is explicitly updated.
 
void registerNamespace (const std::string &prefix, csr uri)
 
 Xml ()
 Constructor.
 
void open (const Path &fname)
 Open an existing XML file. More...
 
void create (const Path &fname, csr root_element)
 Create a new xml file and document. More...
 
void unpack (XmlBuffer &)
 Create a document from the content of a buffer.
 
void freeDoc ()
 release the document from memory
 
void setProp (xmlNodePtr node, csr prop, csr val)
 Set a string property. More...
 
void setProp (xmlNodePtr node, csr prop, int val)
 Set an integer property. More...
 
void setProp (xmlNodePtr node, csr prop, double val)
 Set a double property. More...
 
void setContent (xmlNodePtr node, csr text)
 Set the content for the node. More...
 
void setCDATAContent (xmlNodePtr node, csr text)
 Set the content for the node using CDATA. More...
 
void getPropString (xmlNodePtr node, csr prop, std::string &val)
 Get the property value as a string. More...
 
void getPropInt (xmlNodePtr node, csr prop, int &val)
 Get the property value as an integer. More...
 
void getPropShort (xmlNodePtr node, csr prop, short &val)
 Get the property value as a short integer. More...
 
void getPropDouble (xmlNodePtr node, csr prop, double &val)
 Get the property value as a double. More...
 
std::string getNodeContent (xmlNodePtr p, int expand=1) const
 Get the content of the node. More...
 
std::string getNodeName (xmlNodePtr p) const
 Get the name of the node. More...
 
xmlNodePtr getRoot ()
 Get the root node.
 
xmlNodePtr getChild (xmlNodePtr node, csr name) const
 Get a child node by name. More...
 
int getChildren (xmlNodePtr node, std::vector< xmlNodePtr > &nodes) const
 Get the children of the node. More...
 
xmlNodePtr newNode (xmlNodePtr node, csr name)
 Create a new node. More...
 
void deleteNode (xmlNodePtr node)
 Delete a node and all of its children. More...
 
int find (csr xpath_expression, std::vector< xmlNodePtr > &nodes)
 Find nodes matching an XPath. More...
 

Static Protected Member Functions

static xmlNodePtr newTextChild (xmlNodePtr node, csr name, csr text)
 Create a new node with text content. More...
 

Protected Attributes

Path mFilename
 the XML file that the object represents
 
struct stat xmlStat
 time the file was last accessed by us
 
xmlDocPtr mDoc
 pointer to the root document object
 
xmlXPathContextPtr mCtx
 XML XPath context.
 
bool mDirty
 true when an update has been made, and saving is required.
 
bool mIsOpen
 true if the file is open
 
int mCompression
 0 is uncompressed, thru 9 for max zlib compression
 

Static Protected Attributes

static const int UMASK_RW_RW_R = 0664 ^ 0777
 Default umask for xml files created.
 
static bool xpathinit = false
 flag to indicate if xpath has been initialized
 

Detailed Description

A C++ wrapper for libxml2.

The Xml class provides an object oriented wrapper for the libxml2 library. Applications will subclass this class to provide application specific functions for accessing the XML data.

Member Function Documentation

void Xml::create ( const Path fname,
csr  root_element 
)
protected

Create a new xml file and document.

Parameters
fnamethe name of the file which will be created on save.
root_elementthe name of the root element
void Xml::deleteNode ( xmlNodePtr  node)
protected

Delete a node and all of its children.

Parameters
nodethe document node
bool VICI::cfi::Xml::dirty ( )
inline

Check if the document has been modified.

Returns
true if the document has been modified.
int Xml::find ( csr  xpath_expression,
std::vector< xmlNodePtr > &  nodes 
)
protected

Find nodes matching an XPath.

Parameters
xpath_expressionthe expression to search for.
nodesa vector for the matching nodes.
xmlNodePtr Xml::getChild ( xmlNodePtr  node,
csr  name 
) const
protected

Get a child node by name.

Parameters
nodethe document node
namethe name of the node.
int Xml::getChildren ( xmlNodePtr  node,
std::vector< xmlNodePtr > &  nodes 
) const
protected

Get the children of the node.

Parameters
nodethe document node
nodesa vector for the children nodes.
void Xml::getDtdIdentifiers ( csr  dtdName,
std::string &  publicId,
std::string &  systemId 
)

Get the public identifier for the DTD.

Parameters
dtdNamethe name for the DTD entry
publicIdthe returned public identifier for the DTD
systemIdthe returned system identifier for the DTD
string Xml::getNodeContent ( xmlNodePtr  p,
int  expand = 1 
) const
protected

Get the content of the node.

Parameters
pthe document node
expandif 1 then get the content of child nodes.
string Xml::getNodeName ( xmlNodePtr  p) const
protected

Get the name of the node.

Parameters
pthe document node
void Xml::getPropDouble ( xmlNodePtr  node,
csr  prop,
double &  val 
)
protected

Get the property value as a double.

Parameters
nodethe document node
propthe property name for the element
valthe value for the property
void Xml::getPropInt ( xmlNodePtr  node,
csr  prop,
int &  val 
)
protected

Get the property value as an integer.

Parameters
nodethe document node
propthe property name for the element
valthe value for the property
void Xml::getPropShort ( xmlNodePtr  node,
csr  prop,
short &  val 
)
protected

Get the property value as a short integer.

Parameters
nodethe document node
propthe property name for the element
valthe value for the property
void Xml::getPropString ( xmlNodePtr  node,
csr  prop,
std::string &  val 
)
protected

Get the property value as a string.

Parameters
nodethe document node
propthe property name for the element
valthe value for the property
xmlNodePtr Xml::newNode ( xmlNodePtr  node,
csr  name 
)
protected

Create a new node.

Parameters
nodethe document node
namethe name for new node.
xmlNodePtr Xml::newTextChild ( xmlNodePtr  node,
csr  name,
csr  text 
)
staticprotected

Create a new node with text content.

Parameters
nodethe document node
namethe name for the node.
textthe content for the node.
void Xml::open ( const Path fname)
protected

Open an existing XML file.

Parameters
fnamethe name of the file to open.
void Xml::registerNamespace ( const std::string &  prefix,
csr  uri 
)
protected

Call this to register the prefixes for all uri's used in XPath queries. The prefix does not have to be the same as used in the document and you must supply one for the "anonymous" uri's.

bool Xml::safeToSave ( )

Check if can save without clobbering other input.

Returns
true if its safe to save.
void Xml::save ( const Path fname)

Save the document to a new file.

Parameters
fnamethe new file name.
void Xml::setCDATAContent ( xmlNodePtr  node,
csr  text 
)
protected

Set the content for the node using CDATA.

Parameters
nodethe document node
textthe value to assign to the node.
void Xml::setCompression ( int  rate)

Set the compression rate for saving the document.

Parameters
ratethe required compression factor.
void Xml::setContent ( xmlNodePtr  node,
csr  text 
)
protected

Set the content for the node.

Parameters
nodethe document node
textthe value to assign to the node content.
void VICI::cfi::Xml::setDirty ( bool  dt)
inline

Access to dirty flag if we change document outside of this interface.

Parameters
dtnew value for the dirty flag
void Xml::setDtd ( csr  name,
const Path dtd 
)

Set DTD identifier to dtd, which is just the dtd file name.

Parameters
namethe name for the DTD entry.
dtdThe DTD file name
void Xml::setDtd ( csr  name,
csr  ident,
csr  url 
)

Set DTD identifier.

Parameters
nameThe name for the DTD entry
identThe external id for the entry
urlThe URL of the DTD.
void Xml::setProp ( xmlNodePtr  node,
csr  prop,
csr  val 
)
protected

Set a string property.

Parameters
nodethe document node
propthe property name for the element
valthe value for the property
void Xml::setProp ( xmlNodePtr  node,
csr  prop,
int  val 
)
protected

Set an integer property.

Parameters
nodethe document node
propthe property name for the element
valthe value for the property
void Xml::setProp ( xmlNodePtr  node,
csr  prop,
double  val 
)
protected

Set a double property.

Parameters
nodethe document node
propthe property name for the element
valthe value for the property

The documentation for this class was generated from the following files: