bakery 2.6
|
00001 /* 00002 * Copyright 2000-2002 Murray Cumming 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this library; if not, write to the Free 00016 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef BAKERY_DOCUMENT_XML_H 00020 #define BAKERY_DOCUMENT_XML_H 00021 00022 #include "bakery/Document/Document.h" 00023 #include <libxml++/libxml++.h> 00024 00025 //Features: 00026 //- Read/Write to the Document in terms of XML DOM. 00027 00028 //Future features: 00029 //- Parse the document from disk instad of memory - This *might* allow for very large documents. 00030 00031 namespace Bakery 00032 { 00033 00034 class Document_XML : public Bakery::Document 00035 { 00036 public: 00037 Document_XML(); 00038 virtual ~Document_XML(); 00039 00040 //overrides: 00041 virtual bool load_after(); 00042 virtual bool save_before(); 00043 00044 virtual void set_dtd_name(const std::string& strVal); //e.g. "glom.dtd" 00045 virtual std::string get_dtd_name() const; 00046 00047 virtual void set_dtd_root_node_name(const Glib::ustring& strVal); 00048 virtual Glib::ustring get_dtd_root_node_name() const; 00049 00054 void set_write_formatted(bool formatted = true); 00055 00061 void add_indenting_white_space(); 00062 00063 virtual bool set_xml(const Glib::ustring& strXML); //Parse the XML from the text. 00064 virtual Glib::ustring get_xml() const; //Get the text for the XML. 00065 00066 protected: 00067 static Glib::ustring get_node_attribute_value(const xmlpp::Element* node, const Glib::ustring& strAttributeName); 00068 static void set_node_attribute_value(xmlpp::Element* node, const Glib::ustring& strAttributeName, const Glib::ustring& strValue); 00069 00070 static xmlpp::Element* get_node_child_named(const xmlpp::Element* node, const Glib::ustring& strName); 00071 static xmlpp::Element* get_node_child_named_with_add(xmlpp::Element* node, const Glib::ustring& strName); 00072 00073 virtual const xmlpp::Element* get_node_document() const; //e.g. <glom_document> (root name) 00074 virtual xmlpp::Element* get_node_document(); //e.g. <glom_document> (root name) 00075 00076 virtual void Util_DOM_Write(Glib::ustring& refstrXML) const; 00077 00078 void add_indenting_white_space_to_node(xmlpp::Node* node = 0, const Glib::ustring& start_indent = Glib::ustring()); 00079 00080 typedef Bakery::Document type_base; 00081 00082 //XML Parsing bits: 00083 xmlpp::DomParser m_DOM_Parser; //Could be mutable to allow us to guarantee a root node. 00084 xmlpp::Document* m_pDOM_Document; //1-to-1 with the m_DOM_Parser. 00085 00086 std::string m_strDTD_Name; 00087 Glib::ustring m_strRootNodeName; 00088 bool m_write_formatted; 00089 }; 00090 00091 } //namespace Bakery. 00092 00093 #endif // BAKERY_DOCUMENT_XML_H