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>
25 typedef std::list<XMLNode *> XMLNodeList;
26 typedef std::list<boost::shared_ptr<XMLNode> > XMLSharedNodeList;
27 typedef XMLNodeList::iterator XMLNodeIterator;
28 typedef XMLNodeList::const_iterator XMLNodeConstIterator;
29 typedef std::list<XMLProperty*> XMLPropertyList;
30 typedef XMLPropertyList::iterator XMLPropertyIterator;
31 typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
32 typedef std::map<std::string, XMLProperty*> XMLPropertyMap;
37 XMLTree(const std::string& fn, bool validate = false);
38 XMLTree(const XMLTree*);
41 XMLNode* root() const { return _root; }
42 XMLNode* set_root(XMLNode* n) { return _root = n; }
44 const std::string& filename() const { return _filename; }
45 const std::string& set_filename(const std::string& fn) { return _filename = fn; }
47 int compression() const { return _compression; }
48 int set_compression(int);
50 bool read() { return read_internal(false); }
51 bool read(const std::string& fn) { set_filename(fn); return read_internal(false); }
52 bool read_and_validate() { return read_internal(true); }
53 bool read_and_validate(const std::string& fn) { set_filename(fn); return read_internal(true); }
54 bool read_buffer(const std::string&);
57 bool write(const std::string& fn) { set_filename(fn); return write(); }
59 void debug (FILE*) const;
61 const std::string& write_buffer() const;
64 bool read_internal(bool validate);
66 std::string _filename;
73 XMLNode(const std::string& name);
74 XMLNode(const std::string& name, const std::string& content);
75 XMLNode(const XMLNode& other);
78 const std::string& name() const { return _name; }
80 bool is_content() const { return _is_content; }
81 const std::string& content() const { return _content; }
82 const std::string& set_content(const std::string&);
83 XMLNode* add_content(const std::string& s = std::string());
85 const XMLNodeList& children(const std::string& str = std::string()) const;
86 XMLNode* child(const char*) const;
87 XMLNode* add_child(const char *);
88 XMLNode* add_child_copy(const XMLNode&);
89 void add_child_nocopy(XMLNode&);
91 boost::shared_ptr<XMLSharedNodeList> find(const std::string xpath) const;
92 std::string attribute_value();
94 const XMLPropertyList& properties() const { return _proplist; }
95 XMLProperty* property(const char*);
96 XMLProperty* property(const std::string&);
97 const XMLProperty* property(const char* n) const { return ((XMLNode*)this)->property(n); }
98 const XMLProperty* property(const std::string& n) const { return ((XMLNode*)this)->property(n); }
100 XMLProperty* add_property(const char* name, const std::string& value);
101 XMLProperty* add_property(const char* name, const char* value = "");
102 XMLProperty* add_property(const char* name, const long value);
104 void remove_property(const std::string&);
106 /** Remove all nodes with the name passed to remove_nodes */
107 void remove_nodes(const std::string&);
108 /** Remove and delete all nodes with the name passed to remove_nodes */
109 void remove_nodes_and_delete(const std::string&);
110 /** Remove and delete all nodes with property prop matching val */
111 void remove_nodes_and_delete(const std::string& propname, const std::string& val);
113 void dump (std::ostream &, std::string p = "") const;
118 std::string _content;
119 XMLNodeList _children;
120 XMLPropertyList _proplist;
121 XMLPropertyMap _propmap;
122 mutable XMLNodeList _selected_children;
127 XMLProperty(const std::string& n, const std::string& v = std::string());
130 const std::string& name() const { return _name; }
131 const std::string& value() const { return _value; }
132 const std::string& set_value(const std::string& v) { return _value = v; }
139 class XMLException: public std::exception {
141 explicit XMLException(const std::string msg) : _message(msg) {}
142 virtual ~XMLException() throw() {}
144 virtual const char* what() const throw() { return _message.c_str(); }
147 std::string _message;