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