473,672 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::cop yDom(MSXML2::IX MLDOMDocument *sourceDom,
MSXML2::IXMLDOM Document *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(b str);

bstr = NULL;

}

}

}

catch(...)

{

if (bstr)

{

SysFreeString(b str);

bstr = NULL;

}

}

}



Joe
Nov 12 '05 #1
2 2160
"Joe" <jo****@tssl.co m> wrote in message
news:ON******** ******@TK2MSFTN GP12.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::cop yDom(MSXML2::IX MLDOMDocument *sourceDom,
MSXML2::IXMLDOM Document *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(b str);
bstr = NULL;

}

}

}

catch(...)

{

if (bstr)

{

SysFreeString(b str);
bstr = NULL;

}

}

}



Joe

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

Joe
"Joe Fawcett" <jo********@hot mail.com> ¼¶¼g©ó¶l¥ó·s»D: ed************* *@TK2MSFTNGP09. phx.gbl...
"Joe" <jo****@tssl.co m> wrote in message
news:ON******** ******@TK2MSFTN GP12.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::cop yDom(MSXML2::IX MLDOMDocument *sourceDom,
MSXML2::IXMLDOM Document *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(b str);

bstr = NULL;

}

}

}

catch(...)

{

if (bstr)

{

SysFreeString(b str);

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
9616
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 all the contents of f2 will be created and thrown away. In the case of two StringIO objects, this means there's a point when the contents is held in memory three times.
3
3642
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 my settings if my profile became tampered with or corrupt. Is there any sample code available out there? -Robert
22
6953
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 this option? I assume there isn't but I have to try.
5
17628
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 two questions: 1. Is it generally safe to "overlay" the structure on the buffer, e.g.: unsigned char buffer;
4
1255
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 until the copy finishes. Any ideas? Thank you
6
2556
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 empty Institution to another empty Institution, using the following routine: Private Sub CopyObject(ByRef FromObject As Object, ByRef ToObject As Object) Dim m As New MemoryStream Dim b As New BinaryFormatter
10
7827
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 'to.txt' I specify where to copy it - After I read content of 'to.txt' I create one more subfolder named by current date and thats where everything gets to be copied
6
4971
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, or i couldn't find sth which give totalbytes/written bytes class. And does system.io.file class provide awaring of the chunks / bytes of the files bytes which are written?
2
2806
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 "Graphics" object to wrap around the image (!). It's not so simple as shown in most examples (where they have a simple image file and hard copy it into a harddrive along the lines of : image.Save(@"C:\\temp\\myimage.pgn"); That will work, but it's a...
0
8488
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8411
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8932
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8832
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7449
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6240
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4424
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2821
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.