Re: [xml] Re: Converting text to CDATA



On Sat, May 07, 2005 at 08:17:11PM -0700, Octavian Afilipoai wrote:
For some reason my message was send corrupted the
first time

What is the best way to use CDATA blocks to
encapsulate the text?

Right now I do something like this in order to fill in
my_node with some_string:

xmlNodeSetContent(my_node, BAD_CAST
some_string.c_str());

I could manually add the CDATA identifiers like
this:

xmlNodeSetContent(my_node,BAD_CAST ("<![CDATA +
some_string + "]]").c_str());

  that's wrong. You just generate a broken tree, and even when 
serializing that should not work as < would be escaped.

but I am thinking that libxml should supply some
utilities to do this auautomatically and I just could
not find them

  include/libxml/tree.h
xmlNodePtr XMLCALL xmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len);

  If you use the search engine on xmlsoft.org selecting the XML API and
lookup for CData it's show up on the 12th line:

   http://xmlsoft.org/search.php?query=CData&scope=XMLAPI

"10 xmlNewCDataBlock function tree Creation of a new node containing a CDATA block"

Daniel

-- 
Daniel Veillard      | Red Hat Desktop team http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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