VICI
0.11.815
Visual Chart Interpreter
|
A C++ wrapper for libxml2. More...
#include <vici/xml.h>
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 | |
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.
Create a new xml file and document.
fname | the name of the file which will be created on save. |
root_element | the name of the root element |
|
protected |
Delete a node and all of its children.
node | the document node |
|
inline |
Check if the document has been modified.
|
protected |
Find nodes matching an XPath.
xpath_expression | the expression to search for. |
nodes | a vector for the matching nodes. |
|
protected |
Get a child node by name.
node | the document node |
name | the name of the node. |
|
protected |
Get the children of the node.
node | the document node |
nodes | a vector for the children nodes. |
void Xml::getDtdIdentifiers | ( | csr | dtdName, |
std::string & | publicId, | ||
std::string & | systemId | ||
) |
Get the public identifier for the DTD.
dtdName | the name for the DTD entry |
publicId | the returned public identifier for the DTD |
systemId | the returned system identifier for the DTD |
|
protected |
Get the content of the node.
p | the document node |
expand | if 1 then get the content of child nodes. |
|
protected |
Get the name of the node.
p | the document node |
|
protected |
Get the property value as a double.
node | the document node |
prop | the property name for the element |
val | the value for the property |
|
protected |
Get the property value as an integer.
node | the document node |
prop | the property name for the element |
val | the value for the property |
|
protected |
Get the property value as a short integer.
node | the document node |
prop | the property name for the element |
val | the value for the property |
|
protected |
Get the property value as a string.
node | the document node |
prop | the property name for the element |
val | the value for the property |
|
protected |
Create a new node.
node | the document node |
name | the name for new node. |
Create a new node with text content.
node | the document node |
name | the name for the node. |
text | the content for the node. |
|
protected |
Open an existing XML file.
fname | the name of the file to open. |
|
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.
void Xml::save | ( | const Path & | fname | ) |
Save the document to a new file.
fname | the new file name. |
|
protected |
Set the content for the node using CDATA.
node | the document node |
text | the value to assign to the node. |
void Xml::setCompression | ( | int | rate | ) |
Set the compression rate for saving the document.
rate | the required compression factor. |
|
protected |
Set the content for the node.
node | the document node |
text | the value to assign to the node content. |
|
inline |
Access to dirty flag if we change document outside of this interface.
dt | new value for the dirty flag |
Set DTD identifier to dtd, which is just the dtd file name.
name | the name for the DTD entry. |
dtd | The DTD file name |
Set DTD identifier.
name | The name for the DTD entry |
ident | The external id for the entry |
url | The URL of the DTD. |
Set a string property.
node | the document node |
prop | the property name for the element |
val | the value for the property |
|
protected |
Set an integer property.
node | the document node |
prop | the property name for the element |
val | the value for the property |
|
protected |
Set a double property.
node | the document node |
prop | the property name for the element |
val | the value for the property |