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;
63 boost::shared_ptr<XMLSharedNodeList> find(const std::string xpath, XMLNode* = 0) const;
66 bool read_internal(bool validate);
68 std::string _filename;
76 XMLNode(const std::string& name);
77 XMLNode(const std::string& name, const std::string& content);
78 XMLNode(const XMLNode& other);
81 XMLNode& operator= (const XMLNode& other);
83 const std::string& name() const { return _name; }
85 bool is_content() const { return _is_content; }
86 const std::string& content() const { return _content; }
87 const std::string& set_content(const std::string&);
88 XMLNode* add_content(const std::string& s = std::string());
90 const XMLNodeList& children(const std::string& str = std::string()) const;
91 XMLNode* child(const char*) const;
92 XMLNode* add_child(const char *);
93 XMLNode* add_child_copy(const XMLNode&);
94 void add_child_nocopy(XMLNode&);
96 std::string attribute_value();
98 const XMLPropertyList& properties() const { return _proplist; }
99 XMLProperty* property(const char*);
100 XMLProperty* property(const std::string&);
101 const XMLProperty* property(const char* n) const { return const_cast<XMLNode*>(this)->property(n); }
102 const XMLProperty* property(const std::string& n) const { return const_cast<XMLNode*>(this)->property(n); }
104 XMLProperty* add_property(const char* name, const std::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 std::string&);
109 void remove_property_recursively(const std::string&);
111 /** Remove all nodes with the name passed to remove_nodes */
112 void remove_nodes(const std::string&);
113 /** Remove and delete all nodes with the name passed to remove_nodes */
114 void remove_nodes_and_delete(const std::string&);
115 /** Remove and delete all nodes with property prop matching val */
116 void remove_nodes_and_delete(const std::string& propname, const std::string& val);
118 void dump (std::ostream &, std::string p = "") const;
123 std::string _content;
124 XMLNodeList _children;
125 XMLPropertyList _proplist;
126 XMLPropertyMap _propmap;
127 mutable XMLNodeList _selected_children;
134 XMLProperty(const std::string& n, const std::string& v = std::string());
137 const std::string& name() const { return _name; }
138 const std::string& value() const { return _value; }
139 const std::string& set_value(const std::string& v) { return _value = v; }
146 class XMLException: public std::exception {
148 explicit XMLException(const std::string msg) : _message(msg) {}
149 virtual ~XMLException() throw() {}
151 virtual const char* what() const throw() { return _message.c_str(); }
154 std::string _message;