Re: [xml] xmlNewTextChild without parent parameter



Hello,

        Hi

        We need to create a text node.  Right now we are using xmlNewText, which
does not require knowledge of the parent node.  The problem is that it does
not seem the reserved XML characters ( such as the ampersand ) are
automatically replaced by their XML escaped entity representations.
xmlNewTextChild does do  this, but requires the parent node.  Are there any
functions that just simply create a text node ( like xmlNewText ) with the
XML reserved characters escaped ( like xmlNewTextChild )?  I could not find
any in the documentation or archive.  Thanks.


        Be aware using the last libxml2 version. I've tried the example
below linking against 2.6.7 and, as espected, xmlNewText() has escaped
built-in entities.
        Within xmlNewTextChild()'s guts it uses xmlNewText(). :)
        
#include <stdio.h>
#include <libxml/tree.h>
#include <libxml/parser.h>

int
main (int argc, char **argv)
{
  xmlDocPtr doc;
  xmlNodePtr text_node, child_node, root_node;

  doc = xmlNewDoc ("1.0");
  root_node = xmlNewNode (NULL,"root");
  xmlDocSetRootElement (doc, root_node);

  child_node = xmlNewNode (NULL, "child");
  xmlAddChild (root_node, child_node);

  text_node = xmlNewText ("escaped & < >");
  xmlAddChild (child_node, text_node);
  xmlNewTextChild (root_node,NULL, "child","escaped & < >");

  xmlSaveFormatFileEnc ("-", doc, "UTF-8", 1);
  xmlFreeDoc (doc);
}

--

[]'s
Lucas Brasilino
brasilino recife pe gov br
http://www.recife.pe.gov.br
Emprel -        Empresa Municipal de Informatica (pt_BR)
                Municipal Computing Enterprise (en_US)
Recife - Pernambuco - Brasil
Fone: +55-81-34167078




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