From: <vac...@us...> - 2010-03-11 15:30:20
|
Revision: 176 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=176&view=rev Author: vaclavslavik Date: 2010-03-11 15:30:14 +0000 (Thu, 11 Mar 2010) Log Message: ----------- Add xml::node::set_text_content(). Unlike set_content(), this method expects unescaped text and escapes it properly itself. Modified Paths: -------------- trunk/NEWS trunk/include/xmlwrapp/node.h trunk/src/libxml/node.cxx Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2010-03-11 15:29:43 UTC (rev 175) +++ trunk/NEWS 2010-03-11 15:30:14 UTC (rev 176) @@ -1,4 +1,7 @@ + Added xml::node::set_text_content() for setting unescaped textual + content. + Added xml::exception class, derived from std::runtime_error. Xmlwrapp will throw only this or derived exception, with the exception of std::bad_alloc(), which is still thrown when appropriate. Modified: trunk/include/xmlwrapp/node.h =================================================================== --- trunk/include/xmlwrapp/node.h 2010-03-11 15:29:43 UTC (rev 175) +++ trunk/include/xmlwrapp/node.h 2010-03-11 15:30:14 UTC (rev 176) @@ -287,11 +287,32 @@ entity references, but XML special chars need to be escaped first. In particular, the '&' character @em must be escaped as "&" unless it's part of entity reference. Not escaping - @a content may result in truncation of data. + @a content may result in truncation of data. Use + set_text_content() if @a content may contain special characters. + + @see set_text_content() */ void set_content(const char *content); /** + Set the content of a node to given text. + + In contrast to set_content(), @a content is raw text, so unescaped XML + special chars are allowed and entity references are not supported. + + If this node is an element node, this function will remove all of its + children nodes and replace them with one text node set to the given + string. + + @param content The content text. + + @see set_content() + + @since 0.7.0 + */ + void set_text_content(const char *content); + + /** Get the content for this text node. If this node is not a text node but it has children nodes that are text nodes, the contents of those child nodes will be returned. If there is no content or these Modified: trunk/src/libxml/node.cxx =================================================================== --- trunk/src/libxml/node.cxx 2010-03-11 15:29:43 UTC (rev 175) +++ trunk/src/libxml/node.cxx 2010-03-11 15:30:14 UTC (rev 176) @@ -436,6 +436,16 @@ } +void node::set_text_content(const char *content) +{ + xmlChar *escaped = xmlEncodeSpecialChars(pimpl_->xmlnode_->doc, + reinterpret_cast<const xmlChar*>(content)); + xmlNodeSetContent(pimpl_->xmlnode_, escaped); + if ( escaped ) + xmlFree(escaped); +} + + const char* node::get_content() const { xmlchar_helper content(xmlNodeGetContent(pimpl_->xmlnode_)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |