2
* Copyright 2000-2002 Murray Cumming
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.
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.
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.
19
#ifndef GLOM_BAKERY_DOCUMENT_XML_H
20
#define GLOM_BAKERY_DOCUMENT_XML_H
22
#include <libglom/document/bakery/document.h>
23
#include <libxml++/libxml++.h>
26
//- Read/Write to the Document in terms of XML DOM.
29
//- Parse the document from disk instad of memory - This *might* allow for very large documents.
34
class Document_XML : public GlomBakery::Document
38
virtual ~Document_XML();
41
virtual bool load_after(int& failure_code);
42
virtual bool save_before();
44
void set_dtd_name(const std::string& strVal); //e.g. "glom.dtd"
45
std::string get_dtd_name() const;
47
/** Set the root node name and (optionally) the xmlns ID to be written
48
* when writing the document.
49
* The root node name is also used when reading documents.
51
void set_dtd_root_node_name(const Glib::ustring& strVal, const Glib::ustring& xmlns = Glib::ustring());
53
Glib::ustring get_dtd_root_node_name() const;
55
/** Whether to add extra whitespace when writing the XML to disk.
56
* Do not use this if whitespace is significant in your XML format.
57
* See also add_indenting_white_space().
59
void set_write_formatted(bool formatted = true);
61
/** Put each node on its own line and add white space for indenting,
62
* even if there are child text nodes.
63
* set_write_formatted() does not cause nodes to be indented if there are child text nodes,
64
* because it assumes that the white space is then significant.
66
void add_indenting_white_space();
68
bool set_xml(const Glib::ustring& strXML); //Parse the XML from the text.
69
Glib::ustring get_xml() const; //Get the text for the XML.
72
static Glib::ustring get_node_attribute_value(const xmlpp::Element* node, const Glib::ustring& strAttributeName);
73
static void set_node_attribute_value(xmlpp::Element* node, const Glib::ustring& strAttributeName, const Glib::ustring& strValue);
75
static xmlpp::Element* get_node_child_named(const xmlpp::Element* node, const Glib::ustring& strName);
76
static xmlpp::Element* get_node_child_named_with_add(xmlpp::Element* node, const Glib::ustring& strName);
78
const xmlpp::Element* get_node_document() const; //e.g. <glom_document> (root name)
79
xmlpp::Element* get_node_document(); //e.g. <glom_document> (root name)
81
void Util_DOM_Write(Glib::ustring& refstrXML) const;
83
void add_indenting_white_space_to_node(xmlpp::Node* node = 0, const Glib::ustring& start_indent = Glib::ustring());
85
typedef GlomBakery::Document type_base;
88
xmlpp::DomParser m_DOM_Parser; //Could be mutable to allow us to guarantee a root node.
89
xmlpp::Document* m_pDOM_Document; //1-to-1 with the m_DOM_Parser.
91
std::string m_strDTD_Name;
92
Glib::ustring m_strRootNodeName, m_root_xmlns;
93
bool m_write_formatted;
96
} //namespace GlomBakery.
98
#endif // GLOM_BAKERY_DOCUMENT_XML_H