30 #include <libxml/tree.h>
31 #include <libxml/xpath.h>
32 #include <sys/types.h>
38 #define SASSY_RELEASE "V0.1"
119 void setProp( xmlNodePtr node,
csr prop,
int val );
128 void setProp( xmlNodePtr node,
csr prop,
double val );
206 xmlNodePtr
getChild( xmlNodePtr node,
csr name )
const;
214 int getChildren( xmlNodePtr node, std::vector< xmlNodePtr > & nodes )
const;
221 xmlNodePtr
newNode( xmlNodePtr node,
csr name );
246 int find(
csr xpath_expression, std::vector< xmlNodePtr > & nodes );
A C++ wrapper for libxml2.
Definition: xml.h:55
Path mFilename
the XML file that the object represents
Definition: xml.h:62
void registerNamespace(const std::string &prefix, csr uri)
Definition: xml.cpp:54
void getDtdIdentifiers(csr dtdName, std::string &publicId, std::string &systemId)
Get the public identifier for the DTD.
Definition: xml.cpp:440
void setProp(xmlNodePtr node, csr prop, csr val)
Set a string property.
Definition: xml.cpp:137
void getPropString(xmlNodePtr node, csr prop, std::string &val)
Get the property value as a string.
Definition: xml.cpp:183
void getPropShort(xmlNodePtr node, csr prop, short &val)
Get the property value as a short integer.
Definition: xml.cpp:209
xmlNodePtr getRoot()
Get the root node.
Definition: xml.cpp:277
void getPropDouble(xmlNodePtr node, csr prop, double &val)
Get the property value as a double.
Definition: xml.cpp:229
void create(const Path &fname, csr root_element)
Create a new xml file and document.
Definition: xml.cpp:106
void freeDoc()
release the document from memory
Definition: xml.cpp:123
void setContent(xmlNodePtr node, csr text)
Set the content for the node.
Definition: xml.cpp:166
Manipulate path strings.
Definition: stringy.h:67
virtual ~Xml()
Destructor.
Definition: xml.cpp:372
Xml()
Constructor.
Definition: xml.cpp:66
xmlDocPtr mDoc
pointer to the root document object
Definition: xml.h:64
void getPropInt(xmlNodePtr node, csr prop, int &val)
Get the property value as an integer.
Definition: xml.cpp:196
void open(const Path &fname)
Open an existing XML file.
Definition: xml.cpp:84
bool safeToSave()
Check if can save without clobbering other input.
Definition: xml.cpp:513
void createXPathContext()
Call this whenever mDoc is explicitly updated.
Definition: xml.cpp:41
int mCompression
0 is uncompressed, thru 9 for max zlib compression
Definition: xml.h:100
xmlXPathContextPtr mCtx
XML XPath context.
Definition: xml.h:69
void setCDATAContent(xmlNodePtr node, csr text)
Set the content for the node using CDATA.
Definition: xml.cpp:174
void deleteNode(xmlNodePtr node)
Delete a node and all of its children.
Definition: xml.cpp:333
std::string getNodeContent(xmlNodePtr p, int expand=1) const
Get the content of the node.
Definition: xml.cpp:245
int getChildren(xmlNodePtr node, std::vector< xmlNodePtr > &nodes) const
Get the children of the node.
Definition: xml.cpp:299
xmlNodePtr newNode(xmlNodePtr node, csr name)
Create a new node.
Definition: xml.cpp:313
void setDtd(csr name, const Path &dtd)
Set DTD identifier to dtd, which is just the dtd file name.
Definition: xml.cpp:402
void reload()
Reload the XML file.
Definition: xml.cpp:526
struct stat xmlStat
time the file was last accessed by us
Definition: xml.h:63
static bool xpathinit
flag to indicate if xpath has been initialized
Definition: xml.h:70
int find(csr xpath_expression, std::vector< xmlNodePtr > &nodes)
Find nodes matching an XPath.
Definition: xml.cpp:345
bool mIsOpen
true if the file is open
Definition: xml.h:98
static xmlNodePtr newTextChild(xmlNodePtr node, csr name, csr text)
Create a new node with text content.
Definition: xml.cpp:324
void setCompression(int rate)
Set the compression rate for saving the document.
Definition: xml.cpp:453
const std::string & csr
Save some time typing and shorten parameter lines.
Definition: stringy.h:35
xmlNodePtr getChild(xmlNodePtr node, csr name) const
Get a child node by name.
Definition: xml.cpp:286
std::string getNodeName(xmlNodePtr p) const
Get the name of the node.
Definition: xml.cpp:266
static const int UMASK_RW_RW_R
Default umask for xml files created.
Definition: xml.h:60
bool dirty()
Check if the document has been modified.
Definition: xml.h:294
bool mDirty
true when an update has been made, and saving is required.
Definition: xml.h:97
void save()
Save the document.
Definition: xml.cpp:460
void setDirty(bool dt)
Access to dirty flag if we change document outside of this interface.
Definition: xml.h:300