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

0
mmodrall1 (25)
6/5/2008 4:10:00 PM
dotnet.xml 7266 articles. 0 followers. Follow

4 Replies
945 Views

Similar Articles

[PageSpeed] 26

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: 
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to 
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: =?Utf-8?B?TWFyaw==?= <mmodrall@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
>
>

0
stcheng1 (64)
6/6/2008 5:31:48 AM
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/library/system.xml.xmldocumentfragment.aspx
where you can set the InnerXml property to populate it:
http://msdn.microsoft.com/en-us/library/system.xml.xmldocumentfragment.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/
0
mahotrash (1778)
6/6/2008 12:21:50 PM
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/library/system.xml.xmldocumentfragment.aspx
> where you can set the InnerXml property to populate it:
> http://msdn.microsoft.com/en-us/library/system.xml.xmldocumentfragment.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/
> 
0
mmodrall1 (25)
6/6/2008 1:10:01 PM
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: 
msdnmg@microsoft.com.

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
l@nospam.nospam>
>References:  <94300B79-CCFB-4795-AADD-D3497B59963B@microsoft.com> 
<uGDvn$8xIHA.3384@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/library/system.xml.xmldocumentfragment.aspx
>> where you can set the InnerXml property to populate it:
>> 
http://msdn.microsoft.com/en-us/library/system.xml.xmldocumentfragment.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/
>> 
>

0
stcheng1 (64)
6/9/2008 3:06:24 AM
Reply:

Similar Artilces:

How to use XmlAttributeOverrides
Hi there, I'm trying to use XmlSerializer with overrides to generate xml for a ArrayList that contains objects of a certain type (let's say class A). Class A serializes fine, this is not an issue. The following works fine (the array has an element name ArrayOfAnyType, the containing elements are called anyType): XmlSerializer x = new XmlSerializer(typeof(ArrayList), myTypeArrayContainingA); Now I'm trying XmlAttributeOverrides, so I can control names etc: XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes root = new XmlAttributes(); root.XmlRoot = new ...

How to use Ctrl+Enter in outlook?
I think it's useful but I don't know how to use it.Who will hlp me? "The useful information of outlook" <The useful information of outlook@discussions.microsoft.com> wrote in message news:CBDD662E-8F9B-4F53-B078-506AE4817A3F@microsoft.com... >I think it's useful but I don't know how to use it.Who will hlp me? > 1. Press and hold the Ctrl key. 2. Press and release the Enter key 3. Release the Ctrl key John --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 000775-6, 22/09/2007 Tested on: 9/22/2007 08:51:56 avast! - copyr...

How to paste text into a comment box using toolbar commands
I have a range of cells containing text on one worksheet. I want to paste this text into a Comment Box in a NEW worksheet. Thanks for your help ..... "Halifax" <Halifax@discussions.microsoft.com> wrote in message news:721F3AF2-3E36-4DE8-A083-3475D21FA277@microsoft.com... >I have a range of cells containing text on one worksheet. > I want to paste this text into a Comment Box in a NEW worksheet. > Thanks for your help ..... I don't see the problem. Copy the text, and in the new worksheet paste into a comment... -- Asking a question? Please tell us the version...

Re-arranging table using pivot-table?
I have a worksheet with data organized somewhat like this: New York New York New York Albany Florida Miami Florida Orlando Florida Tampa Florida Jacksonville California Los Angeles California San Diego I need to convert this to a list of states and each city in the columns to the right of their corresponding state. Something like this: New York New York Albany Florida Miami Orlando Tampa Jacksonville California Los Angeles San Diego Any help is greatly appreci...

how to use STATIC control to display temperature in degree (oC)?
I want to use the Static control as a label to display temperature unit in degree (that is oC). How to do that? CString Temp; Temp.Format("%ld%cC",Degrees,0xB0); AliR. "kathy" <yqin_99@yahoo.com> wrote in message news:1129056720.751477.33580@o13g2000cwo.googlegroups.com... > I want to use the Static control as a label to display temperature unit > in degree (that is oC). How to do that? > ...

Re-install Outlook 2002
I am trying to re-install Outlook 2002 for my palm pilot after a crash. The installation will run until I get the message - "another version is already installed and must be uninstalled". The previous version was corrupt and I was unable to uninstall it. Now when I go into the control panel to add/remove the uninstall is no longer in the listed. Help! ...

Outlook rules wizard replies using From field instead of Reply-To address
This is regarding Outlook 2007 and its rules wizard. We have a mail folder with hundreds of emails that were sent on behalf of people. So the "From" and "Reply-To" are different. We created a rule so that we can reply to all of these people but the rules wizard onto uses the From filed when it processes the messages instead of the Reply-To field. This behavior only happens with the rules wizard, we can go through each email, click reply, and get the Reply-To address just fine. I understand there was an article posted by Microsoft about this issue however it was in 2003. I...

Re-Enable CRM User
Hello Everyone, I am trying to enable a disabled CRM user and I received the following error message. Any thoughts or suggestions would be greatly appreciated. [COMException (0x80040204)] Microsoft.Crm.Platform.ComProxy.CBizUserClass.Enable(CUserAuth& Caller, String UserId) +0 Microsoft.Crm.Application.Platform.SystemUser.Activate(String id) +38 Microsoft.Crm.Web.BusinessManagement.SystemUserDetailPage.changeState(Object sender, DataEventArgs e) +127 Microsoft.Crm.Application.Forms.DataEventProcessor.Raise(FormEventId eventId, FormState state, User user, String objectId,...

RE:Excel will not open from a web link
When opening a link on a web page that has an Excel Spreadsheet embedded in it, the spreadsheet will not open up Excel but opens within another browser as an Excel file. Programming on webpage is correct, opens up on other machines just fine. ...

Ron Bovey re: "Trim Selection" in ExcelUtilities
Cells in my Excel spreadsheet appear to be empty. However, when I use Edit/Go To/Special/Blanks, I get "No cells were found". In the past, Ron Bovey suggested going to the WWW.APPROS.COM website, download ExcelUtilities and then use the "Trim Selection" utility to remove the characters that are making the cells not empty. Since then, I've gone to the WWW.APPROS.COM website and downloaded the ASAP Utilities. However, I can seem to find the "Trim Selection" nor any utility that will do the same thing. Help! Try going to Rob (not Ron) Bovey's site: ...

Using EAN barcodes
I am using SO 2.0 SP1. I need to setup some products with EAN13 barcode format. We are contemplating to use GS1 registered barcodes. I was wondering if anybody is using EAN barcodes and if there are any "gotchas" I should look out for. I would probably use a 12-digit product number, which would be good enough for our purpose. Or is there any advantage to use a 13-digit number? I also tried to print some EAN13 labels but did not find a template that prints the item code right underneath the barcode, kind of embedded in the barcode. Is that a special template that need to be us...

Thanks Ken Wright but one more question RE saving data from circular references
Thanks heaps for that macro Ken Wright . I have run it and it works. However it loops forever. Can I set it up so that it could save dat from a certain number of iterations? Thanks again Michae -- Message posted from http://www.ExcelForum.com Hi Michael, If you stayed within your thread and did not change the subject Ken would see your reply as a reply to his reply and would see it a lot faster than when you start a new thread. Ken would probably see your post highlighted in RED. Also someone other than Ken might have been able to help you. (not me I avoid anything that hints of circul...

I need to go back to using my RR email address in RR
I switched my Road Runner email address to Outlook 2007. I no longer receive my emails at RR. How can I switch my email delivery back to RR? Call Road Runner support -- Peter Please Reply to Newsgroup for the benefit of others Requests for assistance by email can not and will not be acknowledged. http://www.microsoft.com/protect "jmc112449" <jmc112449@discussions.microsoft.com> wrote in message news:6FCC0D22-6056-4A2C-9BC1-135BD50E4176@microsoft.com... >I switched my Road Runner email address to Outlook 2007. I no longer receive > my emails at RR. ...

Re: exmerge error
I am getting the following error when trying to use exmerg can anyone please help *************************************************************** Microsoft Exchange Mailbox Merge Program, v4.00.02 Start Logging:February 27, 2004 20:04:3 *************************************************************** [20:04:31] Logging Level: Non [20:04:31] Reading settings from file 'C:\Program Files\Exchsrvr\BIN\EXMERGE.INI' [20:04:32] Error 8007203a opening an LDAP connection. ('LDAP://EXCHANGE/rootDSE') (CADRoutines::GetNamingContextData [20:04:32] Accessing Domain Controller 'PROFI...

Outlook2003 tries to configure itself for using Visio2007 after each start
Hi, I have installed MS Office 2003. Now I have updated my Visio2003 with Visio2007 from MSDNaa. Everything works fine - but I have one annoying issue: After each start of Outlook2003, a dialog appears that wants to configure Outlook for using Visio2007. After this configuration I have to reboot my computer. When I now restart Outlook, the same procedure happens again. This occurs always, when I start Outlook. Is there any possibility to shut off the integrity between Visio and Outlook? Best regards Alex ...

How do I get invisible lines & borders to re-appear?
In Publisher 2003, table grid lines, text box borders and autoshape borders have become invisible on-screen, although they do print out. Any ideas on how to remedy this? Recently installed Adobe PDF Maker which seems to have precipitated this, although it could be entirely co-incidental. Try updating your video drivers. -- JoAnn Paules MVP Microsoft [Publisher] "Ackerman & Co" <Ackerman & Co@discussions.microsoft.com> wrote in message news:0FFE40C2-D6A8-43AE-89E4-061EBB6501DB@microsoft.com... > In Publisher 2003, table grid lines, text box borders and auto...

How do you create resouces to be used
This is a multi-part message in MIME format. ------=_NextPart_000_002F_01C4230B.97650910 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I was told that you can create resources (conference room) to be used = for scheduling. How is this done? Do you lose mailboxes? --=20 BART DANBY ------=_NextPart_000_002F_01C4230B.97650910 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META h...

How to use Live Messenger Web Toolkit to register domain
Hello, i downloaded Live Messenger Web Toolkit sample from here : http://messenger.mslivelabs.com/Samples.zip And i want to just test it, not put it in production. I tried to register application with one of my live application domain(http://quiz.it.msn.com/), but I get error: "Domain does not exist" can you please advice how to get rid of this error....will really appreiciate any immediate reply... ...

re re re ????
nefertiti ??? ...

Animation Using Visio & VBA
I'd like to move an icon (named shIcon) from point A to B, and I can do so by adding in a 1-second delay between moves. The way I've done it is: With shIcon dx = 0.1 * (xLoc - .Cells("pinX")) dy = 0.1 * (yLoc - .Cells("pinY")) For i = 1 To 10 dt1 = Now + 1 / 86400 ' Next 3 lines create a 1-second delay (not the best way to do it, but it works) Do Until Now >= dt1 dx = dx Loop .Cells("pinX") = .Cells("pinX") + dx .Cells("pinY") = .Cells("pinY") + dy Next i End ...

Scratch that, using a filter did not work
I wrote too soon. you can't paste multiple sectors using a filter back to sq 1 HELPPPPPPPPPPPPPPPPP You have replies at your first post. It's better to stay within the same thread. Ben wrote: > > I wrote too soon. you can't paste multiple sectors using a filter back to sq 1 > > HELPPPPPPPPPPPPPPPPP -- Dave Peterson I figured this out after I posted the 3rd note, sorry! Ben "Dave Peterson" wrote: > You have replies at your first post. > > It's better to stay within the same thread. > > Ben wrote: > > > > I wrot...

using ms access as database in windows appplication
i gets " unspecified error" when i inserts new data to database and when i fetches the data from access database is it the problem from access Access Error, No one here can see your monitor.... Please provide Windows version, Access version and what you are doing at the time of the error (ie. opening a form, running a query, etc...). Posting that information increases your odds of getting assistance. -- Gina Whipp "I feel I have been denied critical, need to know, information!" - Tremors II "access error" <access error@discussions.microsoft.com> ...

attempting to use help in Office 2007 goes to the "Configuring ...
I am trying to use the help in various Office apps, but it isn't working. When I click the help, it goes into a "Configuring Microsoft Office Ulitmate 2007..." dialog. After it runs for some period of time, the Microsoft Office Help Viewer window opens. A setup dialog then opens that says "In order to complete setup, a system reboot is necessary. Would you like to reboot now?" If I click No, another setup window pops open that says "Please wait while Windows configures Microsoft Office Word MUI (English) 2007". That disappears and then it s...

Re:
...

Re: Where should be the best place to stored Applcation Data Files?
"Giovanni Dicanio" <gdicanio@_NOSPAM_email_DOT_it> ha scritto nel messaggio news:... > BTW: this post by John Robbins is very interesting reading: > http://www.wintellect.com/CS/blogs/jrobbins/default.aspx copy-and-pasto - the correct link is this: http://www.wintellect.com/CS/blogs/jrobbins/archive/2008/07/10/in-defense-of-vista-and-the-challenges-facing-windows-7.aspx Giovanni And then there's this Vista security discussion from last Friday (cool date, 8/8/8): http://it.slashdot.org/article.pl?sid=08/08/08/1155208 -GB On Fri, 8 Aug 2008 18:50:23 +0200, ...