mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-08 07:45:00 +01:00
Clean up xml++.h and xml++.cc in Ardour style.
No functional changes. (We've diverged far enough for it to not matter, and are about to diverge even more, so might as well). git-svn-id: svn://localhost/ardour2/branches/3.0@4649 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
5b04ddf424
commit
c9e5903e73
2 changed files with 245 additions and 252 deletions
|
|
@ -2,6 +2,7 @@
|
|||
* libxml++ and this file are copyright (C) 2000 by Ari Johnson, and
|
||||
* are covered by the GNU Lesser General Public License, which should be
|
||||
* included with libxml++ as the file COPYING.
|
||||
* Modified for Ardour and released under the same terms.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
|
@ -35,42 +36,84 @@ typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
|
|||
typedef map<string, XMLProperty*> XMLPropertyMap;
|
||||
|
||||
class XMLTree {
|
||||
private:
|
||||
string _filename;
|
||||
XMLNode *_root;
|
||||
int _compression;
|
||||
bool read_internal(bool validate);
|
||||
|
||||
public:
|
||||
XMLTree();
|
||||
XMLTree(const string &fn, bool validate = false);
|
||||
XMLTree(const XMLTree *);
|
||||
XMLTree(const string& fn, bool validate = false);
|
||||
XMLTree(const XMLTree*);
|
||||
~XMLTree();
|
||||
|
||||
XMLNode *root() const { return _root; };
|
||||
XMLNode *set_root(XMLNode *n) { return _root = n; };
|
||||
XMLNode* root() const { return _root; }
|
||||
XMLNode* set_root(XMLNode* n) { return _root = n; }
|
||||
|
||||
const string & filename() const { return _filename; };
|
||||
const string & set_filename(const string &fn) { return _filename = fn; };
|
||||
const string& filename() const { return _filename; }
|
||||
const string& set_filename(const string& fn) { return _filename = fn; }
|
||||
|
||||
int compression() const { return _compression; };
|
||||
int compression() const { return _compression; }
|
||||
int set_compression(int);
|
||||
|
||||
bool read() { return read_internal(false); };
|
||||
bool read(const string &fn) { set_filename(fn); return read_internal(false); };
|
||||
bool read_and_validate() { return read_internal(true); };
|
||||
bool read_and_validate(const string &fn) { set_filename(fn); return read_internal(true); };
|
||||
bool read_buffer(const string &);
|
||||
bool read() { return read_internal(false); }
|
||||
bool read(const string& fn) { set_filename(fn); return read_internal(false); }
|
||||
bool read_and_validate() { return read_internal(true); }
|
||||
bool read_and_validate(const string& fn) { set_filename(fn); return read_internal(true); }
|
||||
bool read_buffer(const string&);
|
||||
|
||||
bool write() const;
|
||||
bool write(const string &fn) { set_filename(fn); return write(); };
|
||||
bool write(const string& fn) { set_filename(fn); return write(); }
|
||||
|
||||
void debug (FILE*) const;
|
||||
|
||||
const string & write_buffer() const;
|
||||
const string& write_buffer() const;
|
||||
|
||||
private:
|
||||
bool read_internal(bool validate);
|
||||
|
||||
string _filename;
|
||||
XMLNode* _root;
|
||||
int _compression;
|
||||
};
|
||||
|
||||
class XMLNode {
|
||||
public:
|
||||
XMLNode(const string& name);
|
||||
XMLNode(const string& name, const string& content);
|
||||
XMLNode(const XMLNode& other);
|
||||
~XMLNode();
|
||||
|
||||
const string& name() const { return _name; }
|
||||
|
||||
bool is_content() const { return _is_content; }
|
||||
const string& content() const { return _content; }
|
||||
const string& set_content(const string&);
|
||||
XMLNode* add_content(const string& s = string());
|
||||
|
||||
const XMLNodeList& children(const string& str = string()) const;
|
||||
XMLNode* child(const char*) const;
|
||||
XMLNode* add_child(const char *);
|
||||
XMLNode* add_child_copy(const XMLNode&);
|
||||
void add_child_nocopy(XMLNode&);
|
||||
|
||||
boost::shared_ptr<XMLSharedNodeList> find(const std::string xpath) const;
|
||||
std::string attribute_value();
|
||||
|
||||
const XMLPropertyList& properties() const { return _proplist; }
|
||||
XMLProperty* property(const char*);
|
||||
XMLProperty* property(const string&);
|
||||
const XMLProperty* property(const char* n) const { return ((XMLNode*)this)->property(n); }
|
||||
const XMLProperty* property(const string& n) const { return ((XMLNode*)this)->property(n); }
|
||||
|
||||
XMLProperty* add_property(const char* name, const string& value);
|
||||
XMLProperty* add_property(const char* name, const char* value = "");
|
||||
XMLProperty* add_property(const char* name, const long value);
|
||||
|
||||
void remove_property(const string&);
|
||||
|
||||
/** Remove all nodes with the name passed to remove_nodes */
|
||||
void remove_nodes(const string&);
|
||||
/** Remove and delete all nodes with the name passed to remove_nodes */
|
||||
void remove_nodes_and_delete(const string&);
|
||||
/** Remove and delete all nodes with property prop matching val */
|
||||
void remove_nodes_and_delete(const string& propname, const string& val);
|
||||
|
||||
private:
|
||||
string _name;
|
||||
bool _is_content;
|
||||
|
|
@ -79,80 +122,31 @@ private:
|
|||
XMLPropertyList _proplist;
|
||||
XMLPropertyMap _propmap;
|
||||
mutable XMLNodeList _selected_children;
|
||||
|
||||
public:
|
||||
XMLNode(const string& name);
|
||||
XMLNode(const string& name, const string& content);
|
||||
XMLNode(const XMLNode& other);
|
||||
~XMLNode();
|
||||
|
||||
const string name() const { return _name; };
|
||||
|
||||
bool is_content() const { return _is_content; };
|
||||
const string & content() const { return _content; };
|
||||
const string & set_content (const string &);
|
||||
XMLNode *add_content(const string & = string());
|
||||
|
||||
const XMLNodeList & children (const string& str = string()) const;
|
||||
XMLNode *add_child (const char *);
|
||||
XMLNode *add_child_copy (const XMLNode&);
|
||||
XMLNode *child (const char*) const;
|
||||
void add_child_nocopy (XMLNode&);
|
||||
|
||||
boost::shared_ptr<XMLSharedNodeList> find(const std::string xpath) const;
|
||||
std::string attribute_value();
|
||||
|
||||
const XMLPropertyList & properties() const { return _proplist; };
|
||||
XMLProperty *property(const char * );
|
||||
XMLProperty *property(const std::string&);
|
||||
const XMLProperty *property(const char * n) const
|
||||
{ return ((XMLNode *) this)->property(n); };
|
||||
const XMLProperty *property(const std::string& ns) const
|
||||
{ return ((XMLNode *) this)->property(ns); };
|
||||
XMLProperty *add_property(const char *name, const string& value);
|
||||
XMLProperty *add_property(const char *name, const char *value = "");
|
||||
XMLProperty *add_property(const char *name, const long value);
|
||||
|
||||
void remove_property(const string &);
|
||||
|
||||
/** Remove all nodes with the name passed to remove_nodes */
|
||||
void remove_nodes(const string &);
|
||||
/** Remove and delete all nodes with the name passed to remove_nodes */
|
||||
void remove_nodes_and_delete(const string &);
|
||||
/** Remove and delete all nodes with property prop matching val */
|
||||
void remove_nodes_and_delete(const string& propname, const string& val);
|
||||
};
|
||||
|
||||
class XMLProperty {
|
||||
public:
|
||||
XMLProperty(const string& n, const string& v = string());
|
||||
~XMLProperty();
|
||||
|
||||
const string& name() const { return _name; }
|
||||
const string& value() const { return _value; }
|
||||
const string& set_value(const string& v) { return _value = v; }
|
||||
|
||||
private:
|
||||
string _name;
|
||||
string _value;
|
||||
|
||||
public:
|
||||
XMLProperty(const string &n, const string &v = string());
|
||||
~XMLProperty();
|
||||
|
||||
const string & name() const { return _name; };
|
||||
const string & value() const { return _value; };
|
||||
const string & set_value(const string &v) { return _value = v; };
|
||||
};
|
||||
|
||||
class XMLException: public std::exception
|
||||
{
|
||||
class XMLException: public std::exception {
|
||||
public:
|
||||
explicit XMLException(const string message)
|
||||
: message_(message)
|
||||
{
|
||||
}
|
||||
explicit XMLException(const string msg) : _message(msg) {}
|
||||
virtual ~XMLException() throw() {}
|
||||
|
||||
virtual ~XMLException() throw() {};
|
||||
|
||||
virtual const char* what() const throw() { return message_.c_str(); }
|
||||
virtual void Raise() const { throw *this; }
|
||||
virtual exception * Clone() const { return new exception(*this); }
|
||||
virtual const char* what() const throw() { return _message.c_str(); }
|
||||
|
||||
private:
|
||||
string message_;
|
||||
string _message;
|
||||
};
|
||||
|
||||
#endif /* __XML_H */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
* libxml++ and this file are copyright (C) 2000 by Ari Johnson, and
|
||||
* are covered by the GNU Lesser General Public License, which should be
|
||||
* included with libxml++ as the file COPYING.
|
||||
* Modified for Ardour and released under the same terms.
|
||||
*/
|
||||
|
||||
#include <pbd/xml++.h>
|
||||
|
|
@ -11,30 +12,30 @@
|
|||
|
||||
#define XML_VERSION "1.0"
|
||||
|
||||
static XMLNode *readnode(xmlNodePtr);
|
||||
static void writenode(xmlDocPtr, XMLNode *, xmlNodePtr, int);
|
||||
static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string xpath);
|
||||
static XMLNode* readnode(xmlNodePtr);
|
||||
static void writenode(xmlDocPtr, XMLNode*, xmlNodePtr, int);
|
||||
static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string& xpath);
|
||||
|
||||
XMLTree::XMLTree()
|
||||
: _filename(),
|
||||
_root(0),
|
||||
_compression(0)
|
||||
: _filename()
|
||||
, _root(0)
|
||||
, _compression(0)
|
||||
{
|
||||
}
|
||||
|
||||
XMLTree::XMLTree(const string &fn, bool validate)
|
||||
: _filename(fn),
|
||||
_root(0),
|
||||
_compression(0)
|
||||
XMLTree::XMLTree(const string& fn, bool validate)
|
||||
: _filename(fn)
|
||||
, _root(0)
|
||||
, _compression(0)
|
||||
{
|
||||
read_internal(validate);
|
||||
}
|
||||
|
||||
XMLTree::XMLTree(const XMLTree * from)
|
||||
XMLTree::XMLTree(const XMLTree* from)
|
||||
: _filename(from->filename())
|
||||
, _root(new XMLNode(*from->root()))
|
||||
, _compression(from->compression())
|
||||
{
|
||||
_filename = from->filename();
|
||||
_root = new XMLNode(*from->root());
|
||||
_compression = from->compression();
|
||||
}
|
||||
|
||||
XMLTree::~XMLTree()
|
||||
|
|
@ -70,7 +71,7 @@ XMLTree::read_internal(bool validate)
|
|||
|
||||
xmlKeepBlanksDefault(0);
|
||||
/* parse the file, activating the DTD validation option */
|
||||
if(validate) {
|
||||
if (validate) {
|
||||
/* create a parser context */
|
||||
ctxt = xmlNewParserCtxt();
|
||||
if (ctxt == NULL) {
|
||||
|
|
@ -83,7 +84,7 @@ XMLTree::read_internal(bool validate)
|
|||
|
||||
/* check if parsing suceeded */
|
||||
if (doc == NULL) {
|
||||
if(validate) {
|
||||
if (validate) {
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -100,7 +101,7 @@ XMLTree::read_internal(bool validate)
|
|||
_root = readnode(xmlDocGetRootElement(doc));
|
||||
|
||||
/* free up the parser context */
|
||||
if(validate) {
|
||||
if (validate) {
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
}
|
||||
xmlFreeDoc(doc);
|
||||
|
|
@ -110,7 +111,7 @@ XMLTree::read_internal(bool validate)
|
|||
}
|
||||
|
||||
bool
|
||||
XMLTree::read_buffer(const string & buffer)
|
||||
XMLTree::read_buffer(const string& buffer)
|
||||
{
|
||||
xmlDocPtr doc;
|
||||
|
||||
|
|
@ -119,7 +120,7 @@ XMLTree::read_buffer(const string & buffer)
|
|||
delete _root;
|
||||
_root = 0;
|
||||
|
||||
doc = xmlParseMemory((char *) buffer.c_str(), buffer.length());
|
||||
doc = xmlParseMemory((char*)buffer.c_str(), buffer.length());
|
||||
if (!doc) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -132,14 +133,14 @@ XMLTree::read_buffer(const string & buffer)
|
|||
|
||||
|
||||
bool
|
||||
XMLTree::write(void) const
|
||||
XMLTree::write() const
|
||||
{
|
||||
xmlDocPtr doc;
|
||||
XMLNodeList children;
|
||||
int result;
|
||||
|
||||
xmlKeepBlanksDefault(0);
|
||||
doc = xmlNewDoc((xmlChar *) XML_VERSION);
|
||||
doc = xmlNewDoc((xmlChar*) XML_VERSION);
|
||||
xmlSetDocCompressMode(doc, _compression);
|
||||
writenode(doc, _root, doc->children, 1);
|
||||
result = xmlSaveFormatFileEnc(_filename.c_str(), doc, "UTF-8", 1);
|
||||
|
|
@ -159,24 +160,24 @@ XMLTree::debug(FILE* out) const
|
|||
XMLNodeList children;
|
||||
|
||||
xmlKeepBlanksDefault(0);
|
||||
doc = xmlNewDoc((xmlChar *) XML_VERSION);
|
||||
doc = xmlNewDoc((xmlChar*) XML_VERSION);
|
||||
xmlSetDocCompressMode(doc, _compression);
|
||||
writenode(doc, _root, doc->children, 1);
|
||||
xmlDebugDumpDocument (out, doc);
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
|
||||
const string &
|
||||
XMLTree::write_buffer(void) const
|
||||
const string&
|
||||
XMLTree::write_buffer() const
|
||||
{
|
||||
static string retval;
|
||||
char *ptr;
|
||||
char* ptr;
|
||||
int len;
|
||||
xmlDocPtr doc;
|
||||
XMLNodeList children;
|
||||
|
||||
xmlKeepBlanksDefault(0);
|
||||
doc = xmlNewDoc((xmlChar *) XML_VERSION);
|
||||
doc = xmlNewDoc((xmlChar*) XML_VERSION);
|
||||
xmlSetDocCompressMode(doc, _compression);
|
||||
writenode(doc, _root, doc->children, 1);
|
||||
xmlDocDumpMemory(doc, (xmlChar **) & ptr, &len);
|
||||
|
|
@ -189,13 +190,16 @@ XMLTree::write_buffer(void) const
|
|||
return retval;
|
||||
}
|
||||
|
||||
XMLNode::XMLNode(const string & n)
|
||||
: _name(n), _is_content(false), _content(string())
|
||||
XMLNode::XMLNode(const string& n)
|
||||
: _name(n)
|
||||
, _is_content(false)
|
||||
{
|
||||
}
|
||||
|
||||
XMLNode::XMLNode(const string & n, const string & c)
|
||||
:_name(n), _is_content(true), _content(c)
|
||||
XMLNode::XMLNode(const string& n, const string& c)
|
||||
: _name(n)
|
||||
, _is_content(true)
|
||||
, _content(c)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -234,8 +238,8 @@ XMLNode::~XMLNode()
|
|||
}
|
||||
}
|
||||
|
||||
const string &
|
||||
XMLNode::set_content(const string & c)
|
||||
const string&
|
||||
XMLNode::set_content(const string& c)
|
||||
{
|
||||
if (c.empty()) {
|
||||
_is_content = false;
|
||||
|
|
@ -249,7 +253,7 @@ XMLNode::set_content(const string & c)
|
|||
}
|
||||
|
||||
XMLNode*
|
||||
XMLNode::child (const char *name) const
|
||||
XMLNode::child (const char* name) const
|
||||
{
|
||||
/* returns first child matching name */
|
||||
|
||||
|
|
@ -268,7 +272,7 @@ XMLNode::child (const char *name) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
const XMLNodeList &
|
||||
const XMLNodeList&
|
||||
XMLNode::children(const string& n) const
|
||||
{
|
||||
/* returns all children matching name */
|
||||
|
|
@ -290,22 +294,22 @@ XMLNode::children(const string& n) const
|
|||
return _selected_children;
|
||||
}
|
||||
|
||||
XMLNode *
|
||||
XMLNode::add_child(const char * n)
|
||||
XMLNode*
|
||||
XMLNode::add_child(const char* n)
|
||||
{
|
||||
return add_child_copy(XMLNode (n));
|
||||
}
|
||||
|
||||
void
|
||||
XMLNode::add_child_nocopy (XMLNode& n)
|
||||
XMLNode::add_child_nocopy(XMLNode& n)
|
||||
{
|
||||
_children.insert(_children.end(), &n);
|
||||
}
|
||||
|
||||
XMLNode *
|
||||
XMLNode*
|
||||
XMLNode::add_child_copy(const XMLNode& n)
|
||||
{
|
||||
XMLNode *copy = new XMLNode (n);
|
||||
XMLNode *copy = new XMLNode(n);
|
||||
_children.insert(_children.end(), copy);
|
||||
return copy;
|
||||
}
|
||||
|
|
@ -313,8 +317,8 @@ XMLNode::add_child_copy(const XMLNode& n)
|
|||
boost::shared_ptr<XMLSharedNodeList>
|
||||
XMLNode::find(const string xpath) const
|
||||
{
|
||||
xmlDocPtr doc = xmlNewDoc((xmlChar *) XML_VERSION);
|
||||
writenode(doc, (XMLNode *) this, doc->children, 1);
|
||||
xmlDocPtr doc = xmlNewDoc((xmlChar*) XML_VERSION);
|
||||
writenode(doc, (XMLNode*)this, doc->children, 1);
|
||||
xmlXPathContext* ctxt = xmlXPathNewContext(doc);
|
||||
|
||||
boost::shared_ptr<XMLSharedNodeList> result =
|
||||
|
|
@ -337,14 +341,14 @@ XMLNode::attribute_value()
|
|||
return child->content();
|
||||
}
|
||||
|
||||
XMLNode *
|
||||
XMLNode::add_content(const string & c)
|
||||
XMLNode*
|
||||
XMLNode::add_content(const string& c)
|
||||
{
|
||||
return add_child_copy(XMLNode (string(), c));
|
||||
}
|
||||
|
||||
XMLProperty *
|
||||
XMLNode::property(const char * n)
|
||||
XMLProperty*
|
||||
XMLNode::property(const char* n)
|
||||
{
|
||||
string ns(n);
|
||||
map<string,XMLProperty*>::iterator iter;
|
||||
|
|
@ -356,8 +360,8 @@ XMLNode::property(const char * n)
|
|||
return 0;
|
||||
}
|
||||
|
||||
XMLProperty *
|
||||
XMLNode::property(const string & ns)
|
||||
XMLProperty*
|
||||
XMLNode::property(const string& ns)
|
||||
{
|
||||
map<string,XMLProperty*>::iterator iter;
|
||||
|
||||
|
|
@ -368,15 +372,15 @@ XMLNode::property(const string & ns)
|
|||
return 0;
|
||||
}
|
||||
|
||||
XMLProperty *
|
||||
XMLNode::add_property(const char * n, const string & v)
|
||||
XMLProperty*
|
||||
XMLNode::add_property(const char* n, const string& v)
|
||||
{
|
||||
string ns(n);
|
||||
if(_propmap.find(ns) != _propmap.end()){
|
||||
if (_propmap.find(ns) != _propmap.end()) {
|
||||
remove_property(ns);
|
||||
}
|
||||
|
||||
XMLProperty *tmp = new XMLProperty(ns, v);
|
||||
XMLProperty* tmp = new XMLProperty(ns, v);
|
||||
|
||||
if (!tmp) {
|
||||
return 0;
|
||||
|
|
@ -388,15 +392,15 @@ XMLNode::add_property(const char * n, const string & v)
|
|||
return tmp;
|
||||
}
|
||||
|
||||
XMLProperty *
|
||||
XMLNode::add_property(const char * n, const char * v)
|
||||
XMLProperty*
|
||||
XMLNode::add_property(const char* n, const char* v)
|
||||
{
|
||||
string vs(v);
|
||||
return add_property(n, vs);
|
||||
}
|
||||
|
||||
XMLProperty *
|
||||
XMLNode::add_property(const char *name, const long value)
|
||||
XMLProperty*
|
||||
XMLNode::add_property(const char* name, const long value)
|
||||
{
|
||||
static char str[1024];
|
||||
snprintf(str, 1024, "%ld", value);
|
||||
|
|
@ -404,7 +408,7 @@ XMLNode::add_property(const char *name, const long value)
|
|||
}
|
||||
|
||||
void
|
||||
XMLNode::remove_property(const string & n)
|
||||
XMLNode::remove_property(const string& n)
|
||||
{
|
||||
if (_propmap.find(n) != _propmap.end()) {
|
||||
_proplist.remove(_propmap[n]);
|
||||
|
|
@ -413,7 +417,7 @@ XMLNode::remove_property(const string & n)
|
|||
}
|
||||
|
||||
void
|
||||
XMLNode::remove_nodes(const string & n)
|
||||
XMLNode::remove_nodes(const string& n)
|
||||
{
|
||||
XMLNodeIterator i = _children.begin();
|
||||
XMLNodeIterator tmp;
|
||||
|
|
@ -429,7 +433,7 @@ XMLNode::remove_nodes(const string & n)
|
|||
}
|
||||
|
||||
void
|
||||
XMLNode::remove_nodes_and_delete(const string & n)
|
||||
XMLNode::remove_nodes_and_delete(const string& n)
|
||||
{
|
||||
XMLNodeIterator i = _children.begin();
|
||||
XMLNodeIterator tmp;
|
||||
|
|
@ -457,7 +461,7 @@ XMLNode::remove_nodes_and_delete(const string& propname, const string& val)
|
|||
++tmp;
|
||||
|
||||
prop = (*i)->property(propname);
|
||||
if(prop && prop->value() == val) {
|
||||
if (prop && prop->value() == val) {
|
||||
delete *i;
|
||||
_children.erase(i);
|
||||
}
|
||||
|
|
@ -466,9 +470,9 @@ XMLNode::remove_nodes_and_delete(const string& propname, const string& val)
|
|||
}
|
||||
}
|
||||
|
||||
XMLProperty::XMLProperty(const string &n, const string &v)
|
||||
: _name(n),
|
||||
_value(v)
|
||||
XMLProperty::XMLProperty(const string& n, const string& v)
|
||||
: _name(n)
|
||||
, _value(v)
|
||||
{
|
||||
// Normalize property name (replace '_' with '-' as old session are inconsistent)
|
||||
for (size_t i = 0; i < _name.length(); ++i) {
|
||||
|
|
@ -482,16 +486,16 @@ XMLProperty::~XMLProperty()
|
|||
{
|
||||
}
|
||||
|
||||
static XMLNode *
|
||||
static XMLNode*
|
||||
readnode(xmlNodePtr node)
|
||||
{
|
||||
string name, content;
|
||||
xmlNodePtr child;
|
||||
XMLNode *tmp;
|
||||
XMLNode* tmp;
|
||||
xmlAttrPtr attr;
|
||||
|
||||
if (node->name) {
|
||||
name = (char *) node->name;
|
||||
name = (char*)node->name;
|
||||
}
|
||||
|
||||
tmp = new XMLNode(name);
|
||||
|
|
@ -499,13 +503,13 @@ readnode(xmlNodePtr node)
|
|||
for (attr = node->properties; attr; attr = attr->next) {
|
||||
content = "";
|
||||
if (attr->children) {
|
||||
content = (char *) attr->children->content;
|
||||
content = (char*)attr->children->content;
|
||||
}
|
||||
tmp->add_property((char *) attr->name, content);
|
||||
tmp->add_property((char*)attr->name, content);
|
||||
}
|
||||
|
||||
if (node->content) {
|
||||
tmp->set_content((char *) node->content);
|
||||
tmp->set_content((char*)node->content);
|
||||
} else {
|
||||
tmp->set_content(string());
|
||||
}
|
||||
|
|
@ -518,7 +522,7 @@ readnode(xmlNodePtr node)
|
|||
}
|
||||
|
||||
static void
|
||||
writenode(xmlDocPtr doc, XMLNode * n, xmlNodePtr p, int root = 0)
|
||||
writenode(xmlDocPtr doc, XMLNode* n, xmlNodePtr p, int root = 0)
|
||||
{
|
||||
XMLPropertyList props;
|
||||
XMLPropertyIterator curprop;
|
||||
|
|
@ -527,19 +531,19 @@ writenode(xmlDocPtr doc, XMLNode * n, xmlNodePtr p, int root = 0)
|
|||
xmlNodePtr node;
|
||||
|
||||
if (root) {
|
||||
node = doc->children = xmlNewDocNode(doc, 0, (xmlChar *) n->name().c_str(), 0);
|
||||
node = doc->children = xmlNewDocNode(doc, 0, (xmlChar*) n->name().c_str(), 0);
|
||||
} else {
|
||||
node = xmlNewChild(p, 0, (xmlChar *) n->name().c_str(), 0);
|
||||
node = xmlNewChild(p, 0, (xmlChar*) n->name().c_str(), 0);
|
||||
}
|
||||
|
||||
if (n->is_content()) {
|
||||
node->type = XML_TEXT_NODE;
|
||||
xmlNodeSetContentLen(node, (const xmlChar *) n->content().c_str(), n->content().length());
|
||||
xmlNodeSetContentLen(node, (const xmlChar*)n->content().c_str(), n->content().length());
|
||||
}
|
||||
|
||||
props = n->properties();
|
||||
for (curprop = props.begin(); curprop != props.end(); ++curprop) {
|
||||
xmlSetProp(node, (xmlChar *) (*curprop)->name().c_str(), (xmlChar *) (*curprop)->value().c_str());
|
||||
xmlSetProp(node, (xmlChar*) (*curprop)->name().c_str(), (xmlChar*) (*curprop)->value().c_str());
|
||||
}
|
||||
|
||||
children = n->children();
|
||||
|
|
@ -548,20 +552,18 @@ writenode(xmlDocPtr doc, XMLNode * n, xmlNodePtr p, int root = 0)
|
|||
}
|
||||
}
|
||||
|
||||
static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string xpath)
|
||||
static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string& xpath)
|
||||
{
|
||||
xmlXPathObject* result = xmlXPathEval((const xmlChar*)xpath.c_str(), ctxt);
|
||||
|
||||
if(!result)
|
||||
{
|
||||
if (!result) {
|
||||
xmlXPathFreeContext(ctxt);
|
||||
xmlFreeDoc(ctxt->doc);
|
||||
|
||||
throw XMLException("Invalid XPath: " + xpath);
|
||||
}
|
||||
|
||||
if(result->type != XPATH_NODESET)
|
||||
{
|
||||
if (result->type != XPATH_NODESET) {
|
||||
xmlXPathFreeObject(result);
|
||||
xmlXPathFreeContext(ctxt);
|
||||
xmlFreeDoc(ctxt->doc);
|
||||
|
|
@ -571,15 +573,12 @@ static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string xpath)
|
|||
|
||||
xmlNodeSet* nodeset = result->nodesetval;
|
||||
XMLSharedNodeList* nodes = new XMLSharedNodeList();
|
||||
if( nodeset )
|
||||
{
|
||||
if (nodeset) {
|
||||
for (int i = 0; i < nodeset->nodeNr; ++i) {
|
||||
XMLNode* node = readnode(nodeset->nodeTab[i]);
|
||||
nodes->push_back(boost::shared_ptr<XMLNode>(node));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// return empty set
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue