Hi,
Im sorry, I must be missing something. I dont understand why you
just cant clone the whole DOMDocument and then make your alterations to
the newly cloned one.
ie.
DOMDocument *doc = parser->getDocument();
DOMDocument *newDoc = (DOMDocument *)doc->cloneNode(doc);
//make some alterations to the newDoc
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMWriter *theSerializer =
((DOMImplementationLS*)impl)->createDOMWriter();
XMLFormatTarget *myFormTarget = new StdOutFormatTarget();
theSerializer->writeNode(myFormTarget, *newDoc);
if you really cant do this then you can just import the comment into the
new doc afterwards. Obviously you could do it better than the following
piece of code :)
DOMDocument *doc = parser->getDocument();
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));
DOMDocument* newDoc = impl->createDocument();
//this is the original comment
DOMNode *com = doc->getFirstChild();
//tis is the imported comment
DOMNode *icom = newDoc->importNode(com, true);
newDoc->appendChild(newDoc->importNode(doc->getDocumentElement(),
true));
//now we insert the comment as a sibling of the doc ele
newDoc->insertBefore(icom, newDoc->getDocumentElement());
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl2 =
DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMWriter *theSerializer =
((DOMImplementationLS*)impl2)->createDOMWriter();
XMLFormatTarget *myFormTarget = new StdOutFormatTarget();
theSerializer->writeNode(myFormTarget, *newDoc);
delete theSerializer;
Gareth
On Thu, 24 Oct 2002, Zdenek Nemec wrote:
> Hi,
> i have a doc in memory and i need to remove lot of nodes from it and save
> the result to a file leaving the source doc in memory untouched.
> Of course i've tried to manually insert all nodes form second level (ie
> after a root(doc) ) as you describe but this wont copy the comment, if i
> clone just a document node then i can't save it into a regular file...
>
> i am not familiar with non-existence of copy-constructor of DOMDocument i
> think it should be useful
>
> zdenek
>
>
> > Hi,
> > why do you want to import the whole document into a newly created
> > document? Is it not OK to just clone the whole thing? If it is not then
> > you could manually insert the nodes into the newly created document by
> > first importing the root element and then inserting the children before
> > it.
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Gareth Reakes, Head of Product Development
DecisionSoft Ltd. http://www.decisionsoft.com
Office: +44 (0) 1865 203192
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]