Re: Element creation
- From: Jayashree <jaya risktechnologysolutions com>
- To: Kjell Ahlstedt <kjell ahlstedt bredband net>
- Cc: libxmlplusplus-list gnome org
- Subject: Re: Element creation
- Date: Wed, 13 Jun 2012 12:40:29 -0400
Kjell,
Thanks for your response. It works fine using the import_node.
I have another question. Does the document object deletes the memory
for all the child nodes, when it goes of our scope or do i need to keep
track of all the node pointers and delete it by myself?
regards,
Jaya
On 06/13/2012 03:57 AM, Kjell Ahlstedt wrote:
Elements and other nodes are supposed to belong to a document. I don't
know if you can create "free-floating" elements, but even if it's
possible, it's probably not a good idea.
My recommendation is that you let getAllNodes() build a document that
contains the elements you want. It shall return xmlpp::Document*. Then
use xmlpp::Node::import_node() to copy the elements to where you want
them.
The example program
http://git.gnome.org/browse/libxml++/tree/examples/import_node shows
how to use import_node(),
and http://git.gnome.org/browse/libxml++/tree/examples/dom_build shows
how to build a document from scratch. The document it builds contains
a lot of stuff that you won't need in your document.
Kjell
2012-06-12 22:58, Jayashree skrev:
Hi,
I need to create a xml document and save it to a file.
I create the xml using the below code.
xmlpp::Document doc;
xmlpp::Element* pRootEle = doc.create_root_node("root");
xmlpp::Element* pNode = pRootEle->add_child("node1");
pNode->add_child_text("node1 data");
But i need to create a list of Elements in a function and directly
add it
as a child to the root node. some thing like below.
list<Element *> eleList = getAllNodes();
foreach(Element ele in eleList)
{
pRootEle -> add_child(ele);
}
How can i achieve it. I don't want to pass the rootnode to the function.
regards,
Jaya
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]