Groups | Blog | Home
all groups > dotnet xml > january 2005 >

dotnet xml : Copying DOM object...help



Joe Fawcett
1/17/2005 9:34:58 AM
[quoted text, click to view]

Use cloneNode(true) on the document.

[quoted text, click to view]

Why? See above. Doing this will also lose encoding information.


--

Joe (MVP - XML)

[quoted text, click to view]

Joe
1/17/2005 10:38:18 AM
Dear All,





Can anyone help me with these two questions? Thank you. I am using MSXML 4.0
SP2 and VC++ .NET.



Q1.

Does anyone know any efficient method of copying the content of one DOM
object to another existing/initialized DOM object? Any sample code will be
most appreciated.





Q2.

I have a piece of code that convert the source DOM into a temp BSTR and then
load the BSTR to the result DOM.



Form the MSXML 4.0 SDK it mentioned that ¡§Calling load or loadXML on an
existing document immediately discards the content of the document.¡¨



My question is will this function cause any memory leak? Since the result
DOM object is already existing/initialized and there is no call to Release
the content of the DOM object.



Void DOMManager::copyDom(MSXML2::IXMLDOMDocument *sourceDom,
MSXML2::IXMLDOMDocument *resultDom)

{

HRESULT hr;

try

{

if (sourceDom && resultDom)

{

BSTR bstr = NULL;

sourceDom->get_xml(&bstr);

VARIANT_BOOL bSuccess =
false;

resultDom->loadXML (bstr,
&bSuccess);

if (bstr)

{

SysFreeString(bstr);

bstr = NULL;

}



}

}

catch(...)

{

if (bstr)

{

SysFreeString(bstr);

bstr = NULL;

}

}

}









Joe

Joe
1/21/2005 10:01:16 AM
thank you very much.

Joe
"Joe Fawcett" <joefawcett@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:ed$vZdH$EHA.1524@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button