472,793 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,793 software developers and data experts.

Copying DOM object...help

Joe
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
Nov 12 '05 #1
2 2122
"Joe" <jo****@tssl.com> wrote in message
news:ON**************@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.

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)
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

Nov 12 '05 #2
Joe
thank you very much.

Joe
"Joe Fawcett" <jo********@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:ed**************@TK2MSFTNGP09.phx.g bl...
"Joe" <jo****@tssl.com> wrote in message
news:ON**************@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.

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)
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


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Thomas Lotze | last post by:
Hi, another question: What's the most efficient way of copying data between two file-like objects? f1.write(f2.read()) doesn't seem to me as efficient as it might be, as a string containing...
3
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore...
22
by: Matt | last post by:
When browsing a web page a user has the ability to highlight content on a page (by holding down the left mouse button and dragging the mouse over the desired content). Is there a way to disable...
5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
4
by: carmen | last post by:
Is it possible to show some movement in the screen while copying a file? I tried to use a timer that change the position of an image but when I start the copy of a file from diskette all is stopped...
6
by: solex | last post by:
Hello, I am trying to use serialization to copy objects. The object in question "Institution" inherits from a parent object "Party" both are marked as <Serializable()>. Initially I can copy an...
10
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in...
6
by: kimiraikkonen | last post by:
Hi, I use system.io.file class to copy files but i have a difficulty about implementing a basic / XP-like progress bar indicator during copying process. My code is this with no progress bar,...
2
by: raylopez99 | last post by:
Beware newbies: I spent a day before I figured this out: copying a bitmap (image) file to file is not quite like copying a text file--you have to do some tricks (see below), like using a...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.