bakery  2.6
Document_XML.h
Go to the documentation of this file.
1 /*
2  * Copyright 2000-2002 Murray Cumming
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #ifndef BAKERY_DOCUMENT_XML_H
20 #define BAKERY_DOCUMENT_XML_H
21 
23 #include <libxml++/libxml++.h>
24 
25 //Features:
26 //- Read/Write to the Document in terms of XML DOM.
27 
28 //Future features:
29 //- Parse the document from disk instad of memory - This *might* allow for very large documents.
30 
31 namespace Bakery
32 {
33 
35 {
36 public:
37  Document_XML();
38  virtual ~Document_XML();
39 
40  //overrides:
41  virtual bool load_after();
42  virtual bool save_before();
43 
44  virtual void set_dtd_name(const std::string& strVal); //e.g. "glom.dtd"
45  virtual std::string get_dtd_name() const;
46 
47  virtual void set_dtd_root_node_name(const Glib::ustring& strVal);
48  virtual Glib::ustring get_dtd_root_node_name() const;
49 
54  void set_write_formatted(bool formatted = true);
55 
62 
63  virtual bool set_xml(const Glib::ustring& strXML); //Parse the XML from the text.
64  virtual Glib::ustring get_xml() const; //Get the text for the XML.
65 
66 protected:
67  static Glib::ustring get_node_attribute_value(const xmlpp::Element* node, const Glib::ustring& strAttributeName);
68  static void set_node_attribute_value(xmlpp::Element* node, const Glib::ustring& strAttributeName, const Glib::ustring& strValue);
69 
70  static xmlpp::Element* get_node_child_named(const xmlpp::Element* node, const Glib::ustring& strName);
71  static xmlpp::Element* get_node_child_named_with_add(xmlpp::Element* node, const Glib::ustring& strName);
72 
73  virtual const xmlpp::Element* get_node_document() const; //e.g. <glom_document> (root name)
74  virtual xmlpp::Element* get_node_document(); //e.g. <glom_document> (root name)
75 
76  virtual void Util_DOM_Write(Glib::ustring& refstrXML) const;
77 
78  void add_indenting_white_space_to_node(xmlpp::Node* node = 0, const Glib::ustring& start_indent = Glib::ustring());
79 
81 
82  //XML Parsing bits:
83  xmlpp::DomParser m_DOM_Parser; //Could be mutable to allow us to guarantee a root node.
84  xmlpp::Document* m_pDOM_Document; //1-to-1 with the m_DOM_Parser.
85 
86  std::string m_strDTD_Name;
87  Glib::ustring m_strRootNodeName;
89 };
90 
91 } //namespace Bakery.
92 
93 #endif // BAKERY_DOCUMENT_XML_H
virtual bool load_after()
Allow app to update icons/title bar.
static xmlpp::Element * get_node_child_named_with_add(xmlpp::Element *node, const Glib::ustring &strName)
virtual void Util_DOM_Write(Glib::ustring &refstrXML) const
void add_indenting_white_space_to_node(xmlpp::Node *node=0, const Glib::ustring &start_indent=Glib::ustring())
virtual const xmlpp::Element * get_node_document() const
void set_write_formatted(bool formatted=true)
Whether to add extra whitespace when writing the XML to disk.
virtual void set_dtd_name(const std::string &strVal)
Definition: Document_XML.h:34
bool m_write_formatted
Definition: Document_XML.h:88
Bakery::Document type_base
Definition: Document_XML.h:80
virtual Glib::ustring get_xml() const
static xmlpp::Element * get_node_child_named(const xmlpp::Element *node, const Glib::ustring &strName)
std::string m_strDTD_Name
Definition: Document_XML.h:86
static void set_node_attribute_value(xmlpp::Element *node, const Glib::ustring &strAttributeName, const Glib::ustring &strValue)
virtual bool save_before()
overrideable.
virtual bool set_xml(const Glib::ustring &strXML)
The Document is like the 'Model' in the Model-View-Controller framework.
Definition: Document.h:34
Definition: App.h:29
virtual Glib::ustring get_dtd_root_node_name() const
void add_indenting_white_space()
Put each node on its own line and add white space for indenting, even if there are child text nodes...
virtual std::string get_dtd_name() const
Glib::ustring m_strRootNodeName
Definition: Document_XML.h:87
xmlpp::Document * m_pDOM_Document
Definition: Document_XML.h:84
static Glib::ustring get_node_attribute_value(const xmlpp::Element *node, const Glib::ustring &strAttributeName)
virtual void set_dtd_root_node_name(const Glib::ustring &strVal)
xmlpp::DomParser m_DOM_Parser
Definition: Document_XML.h:83