[libxml++] Add Element::add_child_cdata().



commit a2b6dd67ab959d8e021ba379bf25471c1023a102
Author: Mathias Lorente <mathias lorente free fr>
Date:   Wed Jul 20 06:43:48 2011 +0200

    Add Element::add_child_cdata().
    
    	* libxml++/nodes/element.[h|cc]: Add add_child_cdata(), using
    	xmlNewCDataBlock(), like the existing add_child_text().
    	* examples/sax_parser_build_dom/example.xml:
    	* examples/sax_parser_build_dom/svgparser.[h|cc]: Use the new API.

 ChangeLog                                  |    9 +++++++++
 examples/sax_parser_build_dom/example.xml  |    1 +
 examples/sax_parser_build_dom/svgparser.cc |    6 ++++++
 examples/sax_parser_build_dom/svgparser.h  |    1 +
 libxml++/nodes/element.cc                  |    7 +++++++
 libxml++/nodes/element.h                   |    7 +++++++
 6 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 33506ba..dd1ac50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-07-20  Mathias Lorente  <mathias lorente free fr>
+
+	Add Element::add_child_cdata().
+
+	* libxml++/nodes/element.[h|cc]: Add add_child_cdata(), using 
+	xmlNewCDataBlock(), like the existing add_child_text().
+	* examples/sax_parser_build_dom/example.xml:
+	* examples/sax_parser_build_dom/svgparser.[h|cc]: Use the new API.
+
 2.34.1:
 
 2011-04-17  Murray Cumming  <murrayc murrayc com>
diff --git a/examples/sax_parser_build_dom/example.xml b/examples/sax_parser_build_dom/example.xml
index 9728dd2..95dae7b 100644
--- a/examples/sax_parser_build_dom/example.xml
+++ b/examples/sax_parser_build_dom/example.xml
@@ -20,4 +20,5 @@
 			</g>
 		</g>
 	</g>
+	<cdata_test><![CDATA[& is not protected here]]></cdata_test>
 </svg>
diff --git a/examples/sax_parser_build_dom/svgparser.cc b/examples/sax_parser_build_dom/svgparser.cc
index 6c0b6a2..90a5ebf 100644
--- a/examples/sax_parser_build_dom/svgparser.cc
+++ b/examples/sax_parser_build_dom/svgparser.cc
@@ -183,4 +183,10 @@ void Parser::on_fatal_error(const Glib::ustring& text)
   std::cout << "on_fatal_error(): " << text << std::endl;
 }
 
+void Parser::on_cdata_block(const Glib::ustring& text)
+{
+  if(!m_context.empty())
+    m_context.top()->add_child_cdata(text);
+}
+
 }
diff --git a/examples/sax_parser_build_dom/svgparser.h b/examples/sax_parser_build_dom/svgparser.h
index ad7a2e8..a036a90 100644
--- a/examples/sax_parser_build_dom/svgparser.h
+++ b/examples/sax_parser_build_dom/svgparser.h
@@ -48,6 +48,7 @@ protected:
   void on_warning(const Glib::ustring& text);
   void on_error(const Glib::ustring& text);
   void on_fatal_error(const Glib::ustring& text);
+  void on_cdata_block(const Glib::ustring& text);
 
 private:
   // context is a stack to keep track of parent node while the SAX parser
diff --git a/libxml++/nodes/element.cc b/libxml++/nodes/element.cc
index 1b9cf96..a798814 100644
--- a/libxml++/nodes/element.cc
+++ b/libxml++/nodes/element.cc
@@ -248,6 +248,13 @@ CommentNode* Element::add_child_comment(const Glib::ustring& content)
 
 
 
+CdataNode* Element::add_child_cdata(const Glib::ustring& content)
+{
+  xmlNode* node = xmlNewCDataBlock(cobj()->doc, (const xmlChar*)content.c_str(), content.bytes());
+  node = xmlAddChild(cobj(), node);
+  Node::create_wrapper(node);
+  return static_cast<CdataNode*>(node->_private);
+}
 
 
 } //namespace xmlpp
diff --git a/libxml++/nodes/element.h b/libxml++/nodes/element.h
index 7fee630..e72b235 100644
--- a/libxml++/nodes/element.h
+++ b/libxml++/nodes/element.h
@@ -10,6 +10,7 @@
 #include <libxml++/nodes/node.h>
 #include <libxml++/attribute.h>
 #include <libxml++/nodes/commentnode.h>
+#include <libxml++/nodes/cdatanode.h>
 
 namespace xmlpp
 {
@@ -134,6 +135,12 @@ public:
    */
   CommentNode* add_child_comment(const Glib::ustring& content);
 
+  /** Append a new CDATA node.
+   * @param content The raw text.
+   * @returns The new CDATA node.
+   */
+  CdataNode* add_child_cdata(const Glib::ustring& content);
+
 protected:
   Glib::ustring get_namespace_uri_for_prefix(const Glib::ustring& ns_prefix) const;
 };



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]