2 * libxml++ and this file are copyright (C) 2000 by Ari Johnson, and
3 * are covered by the GNU Lesser General Public License, which should be
4 * included with libxml++ as the file COPYING.
13 #include <libxml/parser.h>
14 #include <libxml/tree.h>
15 #include <boost/shared_ptr.hpp>
28 typedef list<XMLNode *> XMLNodeList;
29 typedef list<boost::shared_ptr<XMLNode> > XMLSharedNodeList;
30 typedef XMLNodeList::iterator XMLNodeIterator;
31 typedef XMLNodeList::const_iterator XMLNodeConstIterator;
32 typedef list<XMLProperty*> XMLPropertyList;
33 typedef XMLPropertyList::iterator XMLPropertyIterator;
34 typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
35 typedef map<string, XMLProperty*> XMLPropertyMap;
42 bool read_internal(bool validate);
46 XMLTree(const string &fn, bool validate = false);
47 XMLTree(const XMLTree *);
50 XMLNode *root() const { return _root; };
51 XMLNode *set_root(XMLNode *n) { return _root = n; };
53 const string & filename() const { return _filename; };
54 const string & set_filename(const string &fn) { return _filename = fn; };
56 int compression() const { return _compression; };
57 int set_compression(int);
59 bool read() { return read_internal(false); };
60 bool read(const string &fn) { set_filename(fn); return read_internal(false); };
61 bool read_and_validate() { return read_internal(true); };
62 bool read_and_validate(const string &fn) { set_filename(fn); return read_internal(true); };
63 bool read_buffer(const string &);
66 bool write(const string &fn) { set_filename(fn); return write(); };
68 void debug (FILE*) const;
70 const string & write_buffer() const;
78 XMLNodeList _children;
79 XMLPropertyList _proplist;
80 XMLPropertyMap _propmap;
83 XMLNode(const string& name);
84 XMLNode(const string& name, const string& content);
85 XMLNode(const XMLNode& other);
88 const string name() const { return _name; };
90 bool is_content() const { return _is_content; };
91 const string & content() const { return _content; };
92 const string & set_content (const string &);
93 XMLNode *add_content(const string & = string());
95 const XMLNodeList & children (const string& str = string()) const;
96 XMLNode *add_child (const char *);
97 XMLNode *add_child_copy (const XMLNode&);
98 XMLNode *child (const char*) const;
99 void add_child_nocopy (XMLNode&);
101 boost::shared_ptr<XMLSharedNodeList> find(const std::string xpath) const;
102 std::string attribute_value();
104 const XMLPropertyList & properties() const { return _proplist; };
105 XMLProperty *property(const char * );
106 XMLProperty *property(const std::string&);
107 const XMLProperty *property(const char * n) const
108 { return ((XMLNode *) this)->property(n); };
109 const XMLProperty *property(const std::string& ns) const
110 { return ((XMLNode *) this)->property(ns); };
111 XMLProperty *add_property(const char *name, const string& value);
112 XMLProperty *add_property(const char *name, const char *value = "");
113 XMLProperty *add_property(const char *name, const long value);
115 void remove_property(const string &);
117 /** Remove all nodes with the name passed to remove_nodes */
118 void remove_nodes(const string &);
119 /** Remove and delete all nodes with the name passed to remove_nodes */
120 void remove_nodes_and_delete(const string &);
121 /** Remove and delete all nodes with property prop matching val */
122 void remove_nodes_and_delete(const string& propname, const string& val);
131 XMLProperty(const string &n, const string &v = string());
134 const string & name() const { return _name; };
135 const string & value() const { return _value; };
136 const string & set_value(const string &v) { return _value = v; };
139 class XMLException: public std::exception
142 explicit XMLException(const string message)
147 virtual ~XMLException() throw() {};
149 virtual const char* what() const throw() { return message_.c_str(); }
150 virtual void Raise() const { throw *this; }
151 virtual exception * Clone() const { return new exception(*this); }