473,466 Members | 4,850 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 16 '05 #1
1 1404
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 16 '05 #2

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

Similar topics

1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
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...
2
by: Graham Pengelly | last post by:
Hi I am trying to transform on System.Xml.XmlDocument into another using XslTransform without writing the object out to a file. I am guessing it should work something like this... public...
2
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave ...
8
by: pete | last post by:
Hi there, Can someone explain to me why I can't bind to an XmlDocument but I can bind to an XmlNodeList. It's my understanding that they both implement the IEnumerable interface which is...
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...
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... }
3
by: Bob | last post by:
I have a name-value pair type of data that I need to search against. It's to determine what menu item to highlight given the asp.net page name. So the list has all my page names (unique) and the...
5
by: Rob Panosh | last post by:
Hello, I am trying to create a xmlDocument from as dataset. My code is listed below. All seems to go well until xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the following...
2
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) {...
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
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
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
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.