• Page:
  • 1

TOPIC: Combine multiple TXMLDocument's

Combine multiple TXMLDocument's 5 months 6 days ago #14324

C++ Builder first off....

I have a two documents that I need to combine, the master and the external. The master is built as the program progresses, and the external is a returned xml string from a COM object, which I parse into a new TXMLDocument. Everything works as long as I don't want to change the master after I have added the external xml's elements, so this isn't a good solution. Since the document is assigned to the xml element upon creation, and some elements have a different document, and this is where things break.

I don't see any documentation related to reassigning the TXMLDocument. I know I can write some code copy the data from TXMLDocument to TXMLDocumt, however this is a large undertaking as the different type of elements and child elements.

Is there a easy way to fix this?

Please Log in or Create an account to join the conversation.

Combine multiple TXMLDocument's 5 months 3 days ago #14370

Ryan wrote: Everything works as long as I don't want to change the master after I have added the external xml's elements, so this isn't a good solution. Since the document is assigned to the xml element upon creation, and some elements have a different document, and this is where things break.


Try calling DocumentElement.CloneNode(True) on the external document, and then add the clone to the master document.

Ryan wrote: I don't see any documentation related to reassigning the TXMLDocument.


The only way to change a node's owning document is via the IXMLNodeAccess.SetParentNode() method. It assigns the node's OwnerDocument to match the OwnerDocument of the new parent node.

Ryan wrote: I know I can write some code copy the data from TXMLDocument to TXMLDocumt


That is exactly what you need to do.

Ryan wrote: however this is a large undertaking as the different type of elements and child elements.


It is note really that hard. Clone+Add will usually work. So will a simple recursive function, too.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: April Anne