Re: [xml] Pasting fragment

On Fri, Apr 12, 2002 at 03:41:42PM -0500, Matt Cruikshank wrote:

In what seems to be a simple task, I am making many mistakes, and I need

I have an xmlNodePtr, and I have a section of xml text that I would like
to add as a child (or children).

xmlNodePtr activeNode; // somewhere in my document...
std::string newText = "<child>data1</child><child>data2</child>";

My goal is to end up with my activeNode having the two new child nodes as
children, with the corresponding text values, and whatever else may be
inside the newText.

How do I accomplish this?  I don't want to have to parse the text myself,
I want to use something like xmlParseMemory.  But first I need to add a
"<father>" to the front, and "</father>" to the end, so that it would be
a well formed document, right?

  No it's a well balanced chunk. Use
  xmlParseBalancedChunkMemory(xmlDocPtr doc, xmlSAXHandlerPtr sax,
       void *user_data, int depth, const xmlChar *string, xmlNodePtr *lst) {

  xmlNodePtr lst;

  ret = xmlParseBalancedChunkMemory(yourdoc, NULL, NULL, 0, newText, &lst);

  if all goes well, ret is 0 and lst contains a list of nodes you can then
plug in yourdoc.


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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