[quoted text, click to view] "Joe" <joezhu@tssl.com> wrote in message
news:ONXtg2D$EHA.1264@TK2MSFTNGP12.phx.gbl...
> 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.
>
Use cloneNode(true) on the document.
[quoted text, click to view] >
>
>
> 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.
>
Why? See above. Doing this will also lose encoding information.
--
Joe (MVP - XML)
[quoted text, click to view] > 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
>
>