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.
5 * Modified for Ardour and released under the same terms.
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
16 #include <boost/shared_ptr.hpp>
29 typedef list<XMLNode *> XMLNodeList;
30 typedef list<boost::shared_ptr<XMLNode> > XMLSharedNodeList;
31 typedef XMLNodeList::iterator XMLNodeIterator;
32 typedef XMLNodeList::const_iterator XMLNodeConstIterator;
33 typedef list<XMLProperty*> XMLPropertyList;
34 typedef XMLPropertyList::iterator XMLPropertyIterator;
35 typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
36 typedef map<string, XMLProperty*> XMLPropertyMap;
41 XMLTree(const string& fn, bool validate = false);
42 XMLTree(const XMLTree*);
45 XMLNode* root() const { return _root; }
46 XMLNode* set_root(XMLNode* n) { return _root = n; }
48 const string& filename() const { return _filename; }
49 const string& set_filename(const string& fn) { return _filename = fn; }
51 int compression() const { return _compression; }
52 int set_compression(int);
54 bool read() { return read_internal(false); }
55 bool read(const string& fn) { set_filename(fn); return read_internal(false); }
56 bool read_and_validate() { return read_internal(true); }
57 bool read_and_validate(const string& fn) { set_filename(fn); return read_internal(true); }
58 bool read_buffer(const string&);
61 bool write(const string& fn) { set_filename(fn); return write(); }
63 void debug (FILE*) const;
65 const string& write_buffer() const;
68 bool read_internal(bool validate);
77 XMLNode(const string& name);
78 XMLNode(const string& name, const string& content);
79 XMLNode(const XMLNode& other);
82 const string& name() const { return _name; }
84 bool is_content() const { return _is_content; }
85 const string& content() const { return _content; }
86 const string& set_content(const string&);
87 XMLNode* add_content(const string& s = string());
89 const XMLNodeList& children(const string& str = string()) const;
90 XMLNode* child(const char*) const;
91 XMLNode* add_child(const char *);
92 XMLNode* add_child_copy(const XMLNode&);
93 void add_child_nocopy(XMLNode&);
95 boost::shared_ptr<XMLSharedNodeList> find(const std::string xpath) const;
96 std::string attribute_value();
98 const XMLPropertyList& properties() const { return _proplist; }
99 XMLProperty* property(const char*);
100 XMLProperty* property(const string&);
101 const XMLProperty* property(const char* n) const { return ((XMLNode*)this)->property(n); }
102 const XMLProperty* property(const string& n) const { return ((XMLNode*)this)->property(n); }
104 XMLProperty* add_property(const char* name, const string& value);
105 XMLProperty* add_property(const char* name, const char* value = "");
106 XMLProperty* add_property(const char* name, const long value);
108 void remove_property(const string&);
110 /** Remove all nodes with the name passed to remove_nodes */
111 void remove_nodes(const string&);
112 /** Remove and delete all nodes with the name passed to remove_nodes */
113 void remove_nodes_and_delete(const string&);
114 /** Remove and delete all nodes with property prop matching val */
115 void remove_nodes_and_delete(const string& propname, const string& val);
121 XMLNodeList _children;
122 XMLPropertyList _proplist;
123 XMLPropertyMap _propmap;
124 mutable XMLNodeList _selected_children;
129 XMLProperty(const string& n, const string& v = string());
132 const string& name() const { return _name; }
133 const string& value() const { return _value; }
134 const string& set_value(const string& v) { return _value = v; }
141 class XMLException: public std::exception {
143 explicit XMLException(const string msg) : _message(msg) {}
144 virtual ~XMLException() throw() {}
146 virtual const char* what() const throw() { return _message.c_str(); }