Commit 8a4db320 authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming

Added add_child_text() with a previous_node parameter, for adding between

2008-03-26  Murray Cumming  <murrayc@murrayc.com>

* libxml++/nodes/element.cc:
* libxml++/nodes/element.h: Added add_child_text() with a previous_node 
parameter, for adding between existing nodes.
Added add_child_text_before() too.
* libxml++/nodes/node.cc:
* libxml++/nodes/node.h: Added add_child() with a previous_node 
parameter, for adding between existing nodes.
Added add_child_before() too.

* docs/index.html: Removed the license clarifications text because I 
always found it to be arbitrary and not very informative.
* docs/reference/Doxyfile.in: Added a newin2p24 doxygen keyword. 
* docs/reference/Makefile.am: Do not create a version-specific 
directory name for reference documentation. The Since: text and links 
in the documentation are enough to know what was in what version.

svn path=/trunk/; revision=170
parent be7354a2
2008-03-26 Murray Cumming <murrayc@murrayc.com>
* libxml++/nodes/element.cc:
* libxml++/nodes/element.h: Added add_child_text() with a previous_node
parameter, for adding between existing nodes.
Added add_child_text_before() too.
* libxml++/nodes/node.cc:
* libxml++/nodes/node.h: Added add_child() with a previous_node
parameter, for adding between existing nodes.
Added add_child_before() too.
* docs/index.html: Removed the license clarifications text because I
always found it to be arbitrary and not very informative.
* docs/reference/Doxyfile.in: Added a newin2p24 doxygen keyword.
* docs/reference/Makefile.am: Do not create a version-specific
directory name for reference documentation. The Since: text and links
in the documentation are enough to know what was in what version.
2.22.0:
2008-03-07 Deng Xiyue <murrayc@murrayc.com>
......
......@@ -16,50 +16,22 @@ libxml++</h1></center>
<h2>Introduction</h2>
<p>
libxml++ is a C++ wrapper for the <a href="http://www.xmlsoft.org">libxml</a> XML parser library.
Its original author is Ari Johnson and it is currently maintained by Christophe de Vienne and Murray Cumming.
</p>
<h2>License</h2>
<p>Libxml++ is released under the <a href="http://www.gnu.org/licenses/lgpl.html#TOC1">LGPL</a> version 2 or above</p>
<h3>Clarifications</h3>
<p>As requested by some users, here are a few clarifications on the licence:</p>
<ul>
<li>Things that proprietary projects can do:</li>
<ul>
<LI>Deriving sub-classes based on libxml++ classes</LI>
</ul>
<li>Things that proprietary projects cannot do:</li>
<ul>
<li>Change their own copy of libxml++ and distribute object code (for
instance, an application+DLLs that a user installs) for that changed
libxml++, but then refuse to give the changes to people who have received
the object code.</LI></ul>
</ul>
<h2>Download</h2>
<p>You can download libxml++ from <a href="http://ftp.gnome.org/pub/GNOME/sources/libxml++/">here</a>.</p>
<h2>Required Libraries</h2>
<ul>
<li>For libxml++ 1.0
<ul><li><a href="http://www.xmlsoft.org">libxml2</a> &gt;= 2.5.8 </li></ul>
</li>
<li>For libxml++ 2.6 and above
<ul>
<li><a href="http://www.xmlsoft.org/">libxml2</a> &gt;= 2.6.1 </li>
<li><a href="http://www.gtkmm.org/">glibmm-2.4</a> &gt;= 2.4.0 (or a subset of it containing at least Glib::ustring)</li>
</ul>
</li>
<li><a href="http://www.xmlsoft.org/">libxml2</a></li>
<li><a href="http://www.gtkmm.org/">glibmm-2.4</a> (or a subset of it containing at least Glib::ustring)</li>
</ul>
<h2>Documentation</h2>
<p>This short <a href="docs/manual/html/index.html">manual</a> gives an overview of the libxml++ API.</p>
<p>
You can browse online the Reference documentation generated by
<a href="http://www.stack.nl/~dimitri/doxygen/index.html">
<img src="reference/1.0/html/doxygen.png" alt="doxygen" align="middle" border=0 ></a>
<p>The short <a href="docs/manual/html/index.html">manual</a> gives an overview of the libxml++ API. You can also browse online the <a href="docs/reference/stable/html/hierarchy.html">reference documentation</a>.
</p>
<ul>
<li><a href="docs/reference/1.0/html/hierarchy.html">1.0 API</a></li>
<li><a href="docs/reference/stable/html/hierarchy.html">2.14 API</a></li>
</ul>
<h2>Development</h2>
......
......@@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
PROJECT_NAME = @PACKAGE@
PROJECT_NUMBER = @VERSION@
OUTPUT_DIRECTORY = @GENERIC_MAJOR_VERSION@.@GENERIC_MINOR_VERSION@
OUTPUT_DIRECTORY =
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
USE_WINDOWS_ENCODING = NO
......@@ -26,7 +26,8 @@ DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 8
ALIASES = "newin2p18=\xrefitem newin2p18s \"Since libxml++ 2.18\" \"New API in libxml++ 2.18\" \n" \
"newin2p20=\xrefitem newin2p20s \"Since libxml++ 2.20\" \"New API in libxml++ 2.20\" \n" \
"newin2p22=\xrefitem newin2p22s \"Since libxml++ 2.22\" \"New API in libxml++ 2.22\" \n"
"newin2p22=\xrefitem newin2p22s \"Since libxml++ 2.22\" \"New API in libxml++ 2.22\" \n" \
"newin2p24=\xrefitem newin2p24s \"Since libxml++ 2.24\" \"New API in libxml++ 2.24\" \n"
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
SUBGROUPING = YES
......
......@@ -5,24 +5,23 @@ include $(top_srcdir)/docs/Makefile_web.am_fragment
web_path_reference = $(web_path_docs)reference
EXTRA_DIST = README Doxyfile libxml++_doxygen_tags @GENERIC_MAJOR_VERSION@.@GENERIC_MINOR_VERSION@/html \
EXTRA_DIST = README Doxyfile libxml++_doxygen_tags html \
libstdc++.tag.xml
#Ideally, libstdc++.tag.xml would be installed by gcc, instead of being copied into every project.
index_html = @GENERIC_MAJOR_VERSION@.@GENERIC_MINOR_VERSION@/html/index.html
index_html = html/index.html
$(index_html): $(doxygen_configfile_source)
doxygen $(doxygen_configfile)
rm -f stable && ln -s @GENERIC_MAJOR_VERSION@.@GENERIC_MINOR_VERSION@ stable
@GENERIC_MAJOR_VERSION@.@GENERIC_MINOR_VERSION@/html: $(index_html)
html: $(index_html)
libxml++_doxygen_tags: $(index_html)
libxml++-reference-html.tar.gz: $(index_html)
tar cf - @GENERIC_MAJOR_VERSION@.@GENERIC_MINOR_VERSION@/html | gzip -c --best >$@
tar cf - html | gzip -c --best >$@
# Upload to the web site:
......@@ -33,12 +32,12 @@ post-html:
all-local: $(index_html)
doc-clean:
-rm -rf @GENERIC_MAJOR_VERSION@.@GENERIC_MINOR_VERSION@/html
-rm -rf html
-rm -f libxml++_doxygen_tags
-rm -f $libxml++-reference-html.tar.gz
referencedir = $(docdir)/reference/@GENERIC_MAJOR_VERSION@.@GENERIC_MINOR_VERSION@/html
referencedir = $(docdir)/reference/html
install-reference: $(index_html)
@$(NORMAL_INSTALL)
......
......@@ -156,6 +156,40 @@ TextNode* Element::add_child_text(const Glib::ustring& content)
return 0;
}
TextNode* Element::add_child_text(xmlpp::Node* previous_sibling, const Glib::ustring& content)
{
if(!previous_sibling)
return 0;
if(cobj()->type == XML_ELEMENT_NODE)
{
xmlNode* node = xmlNewText((const xmlChar*)content.c_str());
// Use the result, because node can be freed when merging text nodes:
node = xmlAddNextSibling(previous_sibling->cobj(), node);
return static_cast<TextNode*>(node->_private);
}
return 0;
}
TextNode* Element::add_child_text_before(xmlpp::Node* next_sibling, const Glib::ustring& content)
{
if(!next_sibling)
return 0;
if(cobj()->type == XML_ELEMENT_NODE)
{
xmlNode* node = xmlNewText((const xmlChar*)content.c_str());
// Use the result, because node can be freed when merging text nodes:
node = xmlAddPrevSibling(next_sibling->cobj(), node);
return static_cast<TextNode*>(node->_private);
}
return 0;
}
bool Element::has_child_text() const
{
return get_child_text() != 0;
......
......@@ -94,6 +94,26 @@ public:
*/
TextNode* add_child_text(const Glib::ustring& content = Glib::ustring());
/** Add a new text node after the specified existing child node.
*
* @newin2p24
*
* @param previous_sibling An existing child node.
* @param content The text. This should be unescaped - see ContentNode::set_content().
* @returns The new text node.
*/
TextNode* add_child_text(xmlpp::Node* previous_sibling, const Glib::ustring& content = Glib::ustring());
/** Add a new text node before the specified existing child node.
*
* @newin2p24
*
* @param next_sibling An existing child node.
* @param content The text. This should be unescaped - see ContentNode::set_content().
* @returns The new text node.
*/
TextNode* add_child_text_before(xmlpp::Node* next_sibling, const Glib::ustring& content = Glib::ustring());
/** Set the text of the first text node, adding one if necessary.
* This is a convenience method, meant as an alternative to iterating over all the child nodes to find the first suitable node then and setting the text directly.
* @param content The text. This should be unescaped - see ContentNode::set_content().
......
......@@ -97,7 +97,55 @@ const Node::NodeList Node::get_children(const Glib::ustring& name) const
Element* Node::add_child(const Glib::ustring& name,
const Glib::ustring& ns_prefix)
{
xmlNode* node = 0;
_xmlNode* child = create_new_child_node(name, ns_prefix);
if(!child)
return 0;
_xmlNode* node = xmlAddChild(impl_, child);
if(node)
return static_cast<Element*>(node->_private);
else
return 0;
}
Element* Node::add_child(xmlpp::Node* previous_sibling,
const Glib::ustring& name,
const Glib::ustring& ns_prefix)
{
if(!previous_sibling)
return 0;
_xmlNode* child = create_new_child_node(name, ns_prefix);
if(!child)
return 0;
_xmlNode* node = xmlAddNextSibling(previous_sibling->cobj(), child);
if(node)
return static_cast<Element*>(node->_private);
else
return 0;
}
Element* Node::add_child_before(xmlpp::Node* next_sibling,
const Glib::ustring& name,
const Glib::ustring& ns_prefix)
{
if(!next_sibling)
return 0;
_xmlNode* child = create_new_child_node(name, ns_prefix);
if(!child)
return 0;
_xmlNode* node = xmlAddPrevSibling(next_sibling->cobj(), child);
if(node)
return static_cast<Element*>(node->_private);
else
return 0;
}
_xmlNode* Node::create_new_child_node(const Glib::ustring& name, const Glib::ustring& ns_prefix)
{
xmlNs* ns = 0;
if(impl_->type != XML_ELEMENT_NODE)
......@@ -124,14 +172,10 @@ Element* Node::add_child(const Glib::ustring& name,
}
}
node = xmlAddChild(impl_, xmlNewNode(ns, (const xmlChar*)name.c_str()));
if(node)
return static_cast<Element*>(node->_private);
else
return 0;
return xmlNewNode(ns, (const xmlChar*)name.c_str());
}
void Node::remove_child(Node* node)
{
//TODO: Allow a node to be removed without deleting it, to allow it to be moved?
......
......@@ -20,7 +20,8 @@ extern "C" {
}
#endif //DOXYGEN_SHOULD_SKIP_THIS
namespace xmlpp {
namespace xmlpp
{
class TextNode;
class Element;
......@@ -50,7 +51,7 @@ public:
*/
void set_name(const Glib::ustring& name);
/** Set the namespace prefix used by the node
/** Set the namespace prefix used by the node.
* If no such namespace prefix has been declared then this method will throw an exception.
* @param ns_prefix The namespace prefix.
*/
......@@ -64,32 +65,32 @@ public:
*/
int get_line() const;
/** Get the parent element for this node
/** Get the parent element for this node.
* @returns The parent node
*/
const Element* get_parent() const;
/** Get the parent element for this node
/** Get the parent element for this node.
* @returns The parent node
*/
Element* get_parent();
/** Get the next sibling for this node
/** Get the next sibling for this node.
* @returns The next sibling
*/
const Node* get_next_sibling() const;
/** Get the next sibling for this node
/** Get the next sibling for this node.
* @returns The next sibling
*/
Node* get_next_sibling();
/** Get the previous sibling for this node
/** Get the previous sibling for this node .
* @returns The previous sibling
*/
const Node* get_previous_sibling() const;
/** Get the previous sibling for this node
/** Get the previous sibling for this node.
* @returns The previous sibling
*/
Node* get_previous_sibling();
......@@ -106,7 +107,7 @@ public:
*/
const NodeList get_children(const Glib::ustring& name = Glib::ustring()) const;
/** Add a child element to this node
/** Add a child element to this node.
* @param name The new node name
* @param ns_prefix The namespace prefix. If the prefix has not been declared then this method will throw an exception.
* @returns The newly-created element
......@@ -114,6 +115,28 @@ public:
Element* add_child(const Glib::ustring& name,
const Glib::ustring& ns_prefix = Glib::ustring());
/** Add a child element to this node after the specified existing child node.
*
* @newin2p24
*
* @param name The new node name
* @param ns_prefix The namespace prefix. If the prefix has not been declared then this method will throw an exception.
* @returns The newly-created element
*/
Element* add_child(xmlpp::Node* previous_sibling, const Glib::ustring& name,
const Glib::ustring& ns_prefix = Glib::ustring());
/** Add a child element to this node before the specified existing child node.
*
* @newin2p24
*
* @param name The new node name
* @param ns_prefix The namespace prefix. If the prefix has not been declared then this method will throw an exception.
* @returns The newly-created element
*/
Element* add_child_before(xmlpp::Node* next_sibling, const Glib::ustring& name,
const Glib::ustring& ns_prefix = Glib::ustring());
/** Remove the child node.
* @param node The child node to remove. This Node will be deleted and therefore unusable after calling this method.
*/
......@@ -127,12 +150,12 @@ public:
Node* import_node(const Node* node, bool recursive = true);
/** Return the XPath of this node
/** Return the XPath of this node.
* @result The XPath of the node.
*/
Glib::ustring get_path() const;
/** Find nodes from a XPath expression
/** Find nodes from a XPath expression.
* @param xpath The XPath of the nodes.
*/
NodeSet find(const Glib::ustring& xpath) const;
......@@ -141,7 +164,7 @@ public:
*/
typedef std::map<Glib::ustring, Glib::ustring> PrefixNsMap;
/** Find nodes from a XPath expression
/** Find nodes from a XPath expression.
* @param xpath The XPath of the nodes.
* @param namespaces A map of namespace prefixes to namespace URIs to be used while finding.
*/
......@@ -154,6 +177,11 @@ public:
///Access the underlying libxml implementation.
const _xmlNode* cobj() const;
protected:
///Create the C instance ready to be added to the parent node.
_xmlNode* create_new_child_node(const Glib::ustring& name, const Glib::ustring& ns_prefix);
private:
_xmlNode* impl_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment