473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

re-using XmlDocument to load fragments

Hi...

We've got a lot of places in our code where we read relatively small xml
user preference blocks. Currently that's creating a new XmlDocument in every
spot. I was thinking we might see some speed improvements by having one,
central XmlDocument and using doc.ReadNode() to process all of the fragments.

Other than pumping up the NameTable with a mish-mash of different node names
and namespaces, are there any other implications I'm missing?

As an aside, I noticed that doing doc.Load() on a dom more than once keeps
the same NameTable object. What does the XmlDocument do internally with
multiple .Load() calls? Does it empty its internal state object, or just
accrete more?

thanks
Mark

Jun 27 '08 #1
4 3248
Hi Mark,

As for the XmlDocument class, the Load method does do some cleaning up
works such as remove the child nodes and set some properties off. Here is
the code picked from the reflector:
=============
public virtual void Load(XmlReader reader)
{
try
{
this.IsLoading = true;
this.actualLoadingStatus = true;
this.RemoveAll();
this.fEntRefNodesPresent = false;
this.fCDataNodesPresent = false;
this.reportValidity = true;
new XmlLoader().Load(this, reader, this.preserveWhitespace);
}
finally
{
this.IsLoading = false;
this.actualLoadingStatus = false;
this.reportValidity = true;
}
}
==================

Also, the NameTable seems is initialized at XmlDocument's constructor(it
will add some basic namespace mappings there). I think the xmlDocument's
constructor is not very expensive, therefore, if you haven't obviouly
detect performance hit via the XmlDocument creation, I suggest you remain
creating new instance when loading a new xml document/file.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: =?Utf-8?B?TWFyaw==?= <mm******@nospam.nospam>
Subject: re-using XmlDocument to load fragments
Date: Thu, 5 Jun 2008 09:10:00 -0700
>
Hi...

We've got a lot of places in our code where we read relatively small xml
user preference blocks. Currently that's creating a new XmlDocument in
every
>spot. I was thinking we might see some speed improvements by having one,
central XmlDocument and using doc.ReadNode() to process all of the
fragments.
>
Other than pumping up the NameTable with a mish-mash of different node
names
>and namespaces, are there any other implications I'm missing?

As an aside, I noticed that doing doc.Load() on a dom more than once keeps
the same NameTable object. What does the XmlDocument do internally with
multiple .Load() calls? Does it empty its internal state object, or just
accrete more?

thanks
Mark

Jun 27 '08 #2
Mark wrote:
We've got a lot of places in our code where we read relatively small xml
user preference blocks. Currently that's creating a new XmlDocument in every
spot. I was thinking we might see some speed improvements by having one,
central XmlDocument and using doc.ReadNode() to process all of the fragments.
With the DOM implementation there is also XmlDocumentFragment
http://msdn.microsoft.com/en-us/libr...tfragment.aspx
where you can set the InnerXml property to populate it:
http://msdn.microsoft.com/en-us/libr....innerxml.aspx

I haven't done any performance test but XmlDocumentFragment is certainly
meant to parse fragments and then insert them somewhere into the
document tree.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #3
Thank you, Steven and Martin for your responses.

I know this may be a specialized case, but we had implemented jabber http
tunneling originally using a fresh XmlDocument for each request and it was
unusably slow. Wen Yuan pointed me at XmlDocumentFragment and from there I
got to XmlDocument.ReadNode(). Getting away from a fresh document per
request made a *huge* difference in performance.

Now, one of the advantages of that specialized case is that I knew all the
requests were adhering to the same schema, so there would be 100% reuse of
the NameTable and namespace manager. I'm not sure, but I suspect that had a
fair bit to do with the speed improvement.

In another app with more general uses, we have lots and lots of little
XmlDocuments popping in and out of existence to handle user preferences. I
was thinking of applying the same trick there (keeping one or two static xml
docs and using XmlDocumentFragment or ReadNode to process in-coming text).
Since these xml fragments don't come from one coherent schema, I was
wondering if I would likely have the opposite effect - diluting performance
by having a nametable and namespace manager polluted with a lot of different
values.

It would be quite a large undertaking to retool the system, so I was
wondering what the opinions were of those more familiar with the internals of
the System.Xml code...

Thanks
Mark
"Martin Honnen" wrote:
Mark wrote:
We've got a lot of places in our code where we read relatively small xml
user preference blocks. Currently that's creating a new XmlDocument in every
spot. I was thinking we might see some speed improvements by having one,
central XmlDocument and using doc.ReadNode() to process all of the fragments.

With the DOM implementation there is also XmlDocumentFragment
http://msdn.microsoft.com/en-us/libr...tfragment.aspx
where you can set the InnerXml property to populate it:
http://msdn.microsoft.com/en-us/libr....innerxml.aspx

I haven't done any performance test but XmlDocumentFragment is certainly
meant to parse fragments and then insert them somewhere into the
document tree.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #4
Thanks for your reply Mark,

Then, I think your current approach of reusing the xml document object is
reasonable.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
l@nospam.nospam>
>References: <94**********************************@microsoft.co m>
<uG**************@TK2MSFTNGP03.phx.gbl>
>Subject: Re: re-using XmlDocument to load fragments
Date: Fri, 6 Jun 2008 06:10:01 -0700
>
Thank you, Steven and Martin for your responses.

I know this may be a specialized case, but we had implemented jabber http
tunneling originally using a fresh XmlDocument for each request and it was
unusably slow. Wen Yuan pointed me at XmlDocumentFragment and from there
I
>got to XmlDocument.ReadNode(). Getting away from a fresh document per
request made a *huge* difference in performance.

Now, one of the advantages of that specialized case is that I knew all the
requests were adhering to the same schema, so there would be 100% reuse of
the NameTable and namespace manager. I'm not sure, but I suspect that had
a
>fair bit to do with the speed improvement.

In another app with more general uses, we have lots and lots of little
XmlDocuments popping in and out of existence to handle user preferences.
I
>was thinking of applying the same trick there (keeping one or two static
xml
>docs and using XmlDocumentFragment or ReadNode to process in-coming text).
>Since these xml fragments don't come from one coherent schema, I was
wondering if I would likely have the opposite effect - diluting
performance
>by having a nametable and namespace manager polluted with a lot of
different
>values.

It would be quite a large undertaking to retool the system, so I was
wondering what the opinions were of those more familiar with the internals
of
>the System.Xml code...

Thanks
Mark
"Martin Honnen" wrote:
>Mark wrote:
We've got a lot of places in our code where we read relatively small
xml
user preference blocks. Currently that's creating a new XmlDocument
in every
spot. I was thinking we might see some speed improvements by having
one,
central XmlDocument and using doc.ReadNode() to process all of the
fragments.
>>
With the DOM implementation there is also XmlDocumentFragment
http://msdn.microsoft.com/en-us/libr...tfragment.aspx
>where you can set the InnerXml property to populate it:
http://msdn.microsoft.com/en-us/libr...fragment.inner
xml.aspx
>>
I haven't done any performance test but XmlDocumentFragment is certainly
meant to parse fragments and then insert them somewhere into the
document tree.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #5

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

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
1
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
1
by: Clarice Almeida Hughes | last post by:
tenho um index onde tenho o link pro arq css, como sao visualizados pelo include todas as paginas aderem ao css linkado no index. so q eu preciso de alguns links com outras cores no css, o q devo...
2
by: JW | last post by:
I wanted have this as part of a flood control script: <? echo ("Flood control in place - please wait " . $floodinterval . " seconds between postings."); sleep(5); // go back two pages echo...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.