473,624 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Faster XML Processing...

Need some help on how to make the following faster....

Public XmlDocument ProcessXML( XmlDocument xmlData )
{
XmlNode originalXML = xmlData.Clone() ;

try
{
// Process XML data here...
}
catch
{
// if ANYTHING goes wrong with XML processing
// revert back to the original.
xmlData.LoadXml (originalXML.Ou terXml);
return xmlData;
}

return xmlData;
}

There it is. Without cloning and reloading in the catch block, if something
goes wrong, I get SOME xml processing, which I absolutely cannot have. For
example, if some data in the XML is invalid, I throw an exception, but I
still get back all the XML processed before that error ocurred. I need to
either have the entire XML document processed error free, or revert back to
the original (as is being done in the code) if there is any error anywhere.
Can anyone think of a better approach? A faster approach?

Thank you.
Nov 15 '05 #1
5 1744
Generally the XmlTextReader is faster but bit more complicated. Now if you
wish to avoid catching the thrown exception, you can filter the caught
exception to catch certain types of them, or you can have a bool variable
that indicates the exception was caused by an internal function error.
Nov 15 '05 #2
"DMan" <dm**@hotmail.c om> wrote in message news:e$******** *****@tk2msftng p13.phx.gbl...
Public XmlDocument ProcessXML( XmlDocument xmlData )
{
XmlNode originalXML = xmlData.Clone() ; : :
XmlDocument workingXML = xmlData.Clone( ) as XmlDocument;
try
{
// Process XML data here... : :
// Process workingXML here.
}
catch
{
// if ANYTHING goes wrong with XML processing
// revert back to the original.
xmlData.LoadXml (originalXML.Ou terXml);
return xmlData; : :
return xmlData; // pristine document
}

return xmlData; : :
return workingXML; // processed document

: : Can anyone think of a better approach? A faster approach?


Save time by not taking these two expensive steps:

1) converting the node-tree of original XML to string text (OuterXml
is a string),
2) converting that string text back into a node-tree.

Instead, shift your perspective on what the XmlDocument is that you
have cloned. It's not the back-up; it is the work-in-progress. The
serializing to/from string can be eliminated entirely by just choosing
which document to return.

The fact that Clone( ) is virtual (so the upcast is safe as XmlDocument's
Clone( ) returns an XmlNode that is, in fact, an XmlDocument) may
have been responsible for obscuring this approach.
Derek Harmon
Nov 15 '05 #3
Sorry! I otally misunderstood the requirement!
Nov 15 '05 #4
DMan <dm**@hotmail.c om> wrote:
Need some help on how to make the following faster....

Public XmlDocument ProcessXML( XmlDocument xmlData )
{
XmlNode originalXML = xmlData.Clone() ;

try
{
// Process XML data here...
}
catch
{
// if ANYTHING goes wrong with XML processing
// revert back to the original.
xmlData.LoadXml (originalXML.Ou terXml);
return xmlData;
}

return xmlData;
}

There it is. Without cloning and reloading in the catch block, if something
goes wrong, I get SOME xml processing, which I absolutely cannot have. For
example, if some data in the XML is invalid, I throw an exception, but I
still get back all the XML processed before that error ocurred. I need to
either have the entire XML document processed error free, or revert back to
the original (as is being done in the code) if there is any error anywhere.
Can anyone think of a better approach? A faster approach?


Why not just create a new XML document, try to load into that, and if
that fails return the old one? Why try to load it into the original at
all?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message news:MP******** *************** *@msnews.micros oft.com...
Why not just create a new XML document, try to load into that, and if
that fails return the old one? Why try to load it into the original at
all?


My observation is that it's not obvious that XmlNode's Clone( )
method is virtual, returning a polymorphic XmlNode, and that
XmlDocument IS-A XmlNode. If a programmer knows all three
facts and makes a connection between them to the problem,
then an effective solution is obvious.

On the other hand, many developers new to a class design and
driven by necessity will fallback into looking for a way to thunk
from XmlNode into the XmlDocument. The path many choose
(as being more obvious) is OuterXml.

In this specific respect, the XML DOM recommended by the
W3C is less intuitive compared to a model in which polymorphic
types are "in the developer's face." OOP languages make these
principles sublime in their subtlety, and less visible to the untrained
eye. Tools then must pick up the slack, but what tools can fit into
the developers workflow with continuity as they solve this problem?

The .NET Framework SDK documentation does well by listing
inherited members in subclass docs, and that helps (imagine
how unwieldy the docs for XmlValidatingRe ader or PropertyGrid
would be if the SDK didn't document inherited members).

Today, its an issue of developers having to gain experience with
the XML DOM object model, whereupon making the connections
I cite above comeabout naturally with time.

Although the learning curve will solve this for everybody in time,
it's still a good case for motivating the evolution of the object model,
language and tools as they enable more productive developers in
the future (that in turn drive greater ROI for the tasks given them
by their managers, who in turn have larger budgets with which to
purchase new tools).
Derek Harmon
Nov 15 '05 #6

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

Similar topics

6
1237
by: Kamilche | last post by:
I have a routine that I really need, but it slows down processing significantly. Can you spot any ineffeciencies in the code? This code makes a critical function of mine run about 7x slower than using a prebuilt format string. For maximum flexibility, it would be best to calculate the format string using this method, so I'd dearly love to keep it. def fmtstring(args): delim = '\0'
8
1582
by: changereality | last post by:
I am trying to process raw IIS log files and insert them into a MySQL database. I have no problem accomplishing this, but the php code runs very slow. Right now, it is processing 10,000 lines in a log file every ~300 seconds. I am dealing with daily log files with records over 500,000. It takes hours to process a daily file. <?php error_reporting(E_ALL);
0
1089
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... }
7
4088
by: Danny | last post by:
I am trying to process a database and my code does so much that it takes a whle to go through the database. most of it is sql queries, updates and such. For about 6000 records, it takes over a minute to process,maybe 2.5 to 3 minutes. How can I speed it up? I did create an index on some of the search fields, but didnt seem to help. I have a 2.4 mhz machine!!
1
2015
by: Kamyk | last post by:
Hello all! I have such question to all of you. I have some tables linked from MS SQL Server 2000. Is time of processing query based on these linked tables from MS SQL Server 2000, faster or slower than the time of processing the same query based on tables, which are not linked but imported to MS Access?
4
1958
by: sunilkher | last post by:
Here is a small sample program that I have. #include <stdlib.h> #include <pthread.h> #include <string> using namespace std; pthread_t threads; pthread_attr_t thr_attr;
10
2170
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All I am doing is quering the db for all the headers for a certain group and then going through them to find all the parts of each post. I only want ones that are complete. Meaning all segments for that one file posted are there. using System;
16
1602
by: bartj1 | last post by:
Hi, I did a benchmark comparison of a National Instruments Active-x "Strip Chart" control in both Vb5 and vb.net(2005). The code is identical: For I = 1 to 10000 ARR(1,0) = J AxCWGraph1.ChartY(arr) j = J + 1 If j 10 then j = 0
23
2511
by: Python Maniac | last post by:
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80) return s def descrambleLine(line):
28
2430
by: n00m | last post by:
Both codes below read the same huge(~35MB) text file. In the file 1000000 lines, the length of each line < 99 chars. Stable result: Python runs ~0.65s C : ~0.70s Any thoughts?
0
8179
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
8341
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
7174
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
5570
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
4084
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
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2612
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 we have to send another system
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
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.