473,399 Members | 2,774 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,399 software developers and data experts.

Faster way to reconstruct XmlDocument


Hello,

I have profiled my code, and the current performance bottleneck is this
routine. It gets called 7400 times to do some intensive calculations when a
user uses the feature. The xmlText parameter will be used to pass in a xml
document text stored in db, the text contents (about 200 of these guys
total) are stored in a cached static variable. My web app must be
thread-safe, so I cannot create and cache 200 XmlDocument objects because
each thread will do differently to the object it uses including modifying
its content.

1) Is there another implementation that runs faster than what I current have
and still thread-safe?
2) Maybe there is a way to duplicate a XmlDocument object and duplicating it
might be faster, if there is, I could just cache the 200 XmlDocument and
duplicate new one from there as requested.

Thanks for your comments and advice,
zeng
public static XmlDocument CreateXmlDoc( string xmlText )
{
XmlDocument xmlDoc = new XmlDocument();

System.IO.MemoryStream memStream = null;
XmlTextReader readerData = null;

try
{
System.Text.ASCIIEncoding e = new System.Text.ASCIIEncoding();

memStream = new MemoryStream( e.GetBytes( xmlText ) );
readerData = new XmlTextReader( memStream );
xmlDoc.Load( readerData );

}
finally
{
if( null != readerData )
readerData.Close();

if( null != memStream )
memStream.Close();
}
return xmlDoc;
}
Nov 12 '05 #1
1 1281
Hi Zeng,

In dot net you have two basic ways of manipulating a XML DOM, with
Xmldocument and SAX with XML text reader/writer etc..

So if teh requirement is to return a *XmlDocument* I think you may have less
option as far as teh performance increament is concern.. You may define your
XmlDocument object out side of ur method to slightly increase the
performance.. but ..

Depending on your requirement if you can process the data (if a sequencial
data reading) with a sax type reader that may indeed increase the
performance..

Regards,
Nirosh.

"Zeng" <Ze******@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP11.phx.gbl...

Hello,

I have profiled my code, and the current performance bottleneck is this
routine. It gets called 7400 times to do some intensive calculations when a user uses the feature. The xmlText parameter will be used to pass in a xml document text stored in db, the text contents (about 200 of these guys
total) are stored in a cached static variable. My web app must be
thread-safe, so I cannot create and cache 200 XmlDocument objects because
each thread will do differently to the object it uses including modifying
its content.

1) Is there another implementation that runs faster than what I current have and still thread-safe?
2) Maybe there is a way to duplicate a XmlDocument object and duplicating it might be faster, if there is, I could just cache the 200 XmlDocument and
duplicate new one from there as requested.

Thanks for your comments and advice,
zeng
public static XmlDocument CreateXmlDoc( string xmlText )
{
XmlDocument xmlDoc = new XmlDocument();

System.IO.MemoryStream memStream = null;
XmlTextReader readerData = null;

try
{
System.Text.ASCIIEncoding e = new System.Text.ASCIIEncoding();

memStream = new MemoryStream( e.GetBytes( xmlText ) );
readerData = new XmlTextReader( memStream );
xmlDoc.Load( readerData );

}
finally
{
if( null != readerData )
readerData.Close();

if( null != memStream )
memStream.Close();
}
return xmlDoc;
}

Nov 12 '05 #2

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

Similar topics

0
by: DMan | last post by:
Need some help on how to make the following faster.... Public XmlDocument ProcessXML( XmlDocument xmlData ) { XmlNode originalXML = xmlData.Clone(); try { // Process XML data here... }
1
by: John A Grandy | last post by:
working with a local xml file. perform an xpath query and iterate through the resultset to build a virtual DataTable -- each DataRow composed of multiple attributes of each element in the xpath...
5
by: DMan | last post by:
Need some help on how to make the following faster.... Public XmlDocument ProcessXML( XmlDocument xmlData ) { XmlNode originalXML = xmlData.Clone(); try { // Process XML data here... }
1
by: Zeng | last post by:
Hello, I have profiled my code, and the current performance bottleneck is this routine. It gets called 7400 times to do some intensive calculations when a user uses the feature. The xmlText...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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
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...
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...

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.