473,661 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3268
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.actualLoad ingStatus = true;
this.RemoveAll( );
this.fEntRefNod esPresent = false;
this.fCDataNode sPresent = false;
this.reportVali dity = true;
new XmlLoader().Loa d(this, reader, this.preserveWh itespace);
}
finally
{
this.IsLoading = false;
this.actualLoad ingStatus = false;
this.reportVali dity = 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****@microsof t.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******@nospa m.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 XmlDocumentFrag ment
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 XmlDocumentFrag ment 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 XmlDocumentFrag ment and from there I
got to XmlDocument.Rea dNode(). 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 XmlDocumentFrag ment 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 XmlDocumentFrag ment
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 XmlDocumentFrag ment 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****@microsof t.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************ *************** *******@microso ft.com>
<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 XmlDocumentFrag ment and from there
I
>got to XmlDocument.Rea dNode(). 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 XmlDocumentFrag ment 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 XmlDocumentFrag ment
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 XmlDocumentFrag ment 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
4288
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 be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6418
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 well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4090
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 for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
3997
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
18522
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 blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3695
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 sockets??
8
4409
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 image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
1
3630
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 NOT IN ( SELECT manufacturers_id FROM products )
1
3821
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 fazer?
2
5296
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 "<script>window.history.go(-2);</script>"; exit; ?>
0
8343
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,...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7364
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...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
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
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.