XMLTree::XMLTree()
: _filename(),
- _root(),
- _compression(0),
- _initialized(false)
+ _root(0),
+ _compression(0)
{
}
XMLTree::XMLTree(const string &fn)
: _filename(fn),
_root(0),
- _compression(0),
- _initialized(false)
+ _compression(0)
{
read();
}
_filename = from->filename();
_root = new XMLNode(*from->root());
_compression = from->compression();
- _initialized = true;
}
XMLTree::~XMLTree()
{
- if (_initialized && _root)
+ if (_root) {
delete _root;
+ }
}
int
doc = xmlParseFile(_filename.c_str());
if (!doc) {
- _initialized = false;
return false;
}
_root = readnode(xmlDocGetRootElement(doc));
xmlFreeDoc(doc);
- _initialized = true;
return true;
}
doc = xmlParseMemory((char *) buffer.c_str(), buffer.length());
if (!doc) {
- _initialized = false;
return false;
}
_root = readnode(xmlDocGetRootElement(doc));
xmlFreeDoc(doc);
- _initialized = true;
return true;
}
doc = xmlNewDoc((xmlChar *) "1.0");
xmlSetDocCompressMode(doc, _compression);
writenode(doc, _root, doc->children, 1);
- result = xmlSaveFormatFile(_filename.c_str(), doc, 1);
+ result = xmlSaveFormatFileEnc(_filename.c_str(), doc, "UTF-8", 1);
xmlFreeDoc(doc);
if (result == -1) {
XMLNode::XMLNode(const string & n)
: _name(n), _is_content(false), _content(string())
{
- if (_name.empty()) {
- _initialized = false;
- } else {
- _initialized = true;
- }
}
XMLNode::XMLNode(const string & n, const string & c)
:_name(n), _is_content(true), _content(c)
{
- _initialized = true;
}
XMLNode::XMLNode(const XMLNode& from)
- : _initialized(false)
{
XMLPropertyList props;
XMLPropertyIterator curprop;
return _content;
}
+XMLNode*
+XMLNode::child (const char *name) const
+{
+ /* returns first child matching name */
+
+ XMLNodeConstIterator cur;
+
+ if (name == 0) {
+ return 0;
+ }
+
+ for (cur = _children.begin(); cur != _children.end(); ++cur) {
+ if ((*cur)->name() == name) {
+ return *cur;
+ }
+ }
+
+ return 0;
+}
+
const XMLNodeList &
-XMLNode::children(const string & n) const
+XMLNode::children(const string& n) const
{
- static XMLNodeList retval;
+ /* returns all children matching name */
+
XMLNodeConstIterator cur;
- if (n.length() == 0) {
+ if (n.empty()) {
return _children;
}
-
- retval.erase(retval.begin(), retval.end());
+
+ _selected_children.clear();
for (cur = _children.begin(); cur != _children.end(); ++cur) {
if ((*cur)->name() == n) {
- retval.insert(retval.end(), *cur);
+ _selected_children.insert(_selected_children.end(), *cur);
}
}
- return retval;
+ return _selected_children;
}
XMLNode *
XMLNode::property(const char * n)
{
string ns(n);
- if (_propmap.find(ns) == _propmap.end()) {
- return 0;
+ map<string,XMLProperty*>::iterator iter;
+
+ if ((iter = _propmap.find(ns)) != _propmap.end()) {
+ return iter->second;
+ }
+
+ return 0;
+}
+
+XMLProperty *
+XMLNode::property(const string & ns)
+{
+ map<string,XMLProperty*>::iterator iter;
+
+ if ((iter = _propmap.find(ns)) != _propmap.end()) {
+ return iter->second;
}
- return _propmap[ns];
+ return 0;
}
XMLProperty *