473,503 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Performance of XmlDocument.ImportNode

I am using C# to write an application that migrates documents from one
version of an XML schema/DTD to later one. Much of the document has the same
structure in the two versions and I use XMLDocument.ImportNode to copy
unchanged sub-trees between the old and new document but this takes much
longer than it should.

I profiled the code and found that when ImportNode copies an element it
initialises any default attributes defined for the element in the schema.
This task appears to reinvoke the XML parser (via InnerText) rather than
create object instances directly. The result is that a an operation that
should complete in milliseconds is currently taking 3 seconds per document.

How can I configure an XmlDocument so that default attributes are not
initialised as XmlElement instances are created?

Thanks
Nov 12 '05 #1
1 4322
After more profiling I found the cause of the performance loss.

If you are creating elements in an XmlDocument that has an associated
XmlDocumentType then the code searches the XML grammar (DTD or schema) and
creates an default attributes defined by the new element. If the document
has a DTD based grammar then this operation will cause the element
definitions to be parsed on each invocation - hence the loss of performance
I was experiencing.

In my code I added some lines to temporarily remove the XmlDocumentType from
the document before creating the new elements. I re-insert the
XmlDocumentType node when all the changes are complete. The ImportNode
method now executes as it should in milliseconds rather than seconds. I have
not tried profile the ImportNode operation on a document that has an XML
schema defined grammar. Obviously the resulting XmlDocument structure is a
little different, but default attribute values can easily be corrected
during subsequent processing.

For a simple DTD based grammar the performance loss might not as large as it
was in my case (my target DTD was 50K of definitions, my instance document
as 22K).

"Andrew Jacobs" <an****@im.not.telling.you.com> wrote in message
news:9K**************@newsfe2-win.ntli.net...
I am using C# to write an application that migrates documents from one
version of an XML schema/DTD to later one. Much of the document has the
same structure in the two versions and I use XMLDocument.ImportNode to copy
unchanged sub-trees between the old and new document but this takes much
longer than it should.

I profiled the code and found that when ImportNode copies an element it
initialises any default attributes defined for the element in the schema.
This task appears to reinvoke the XML parser (via InnerText) rather than
create object instances directly. The result is that a an operation that
should complete in milliseconds is currently taking 3 seconds per
document.

How can I configure an XmlDocument so that default attributes are not
initialised as XmlElement instances are created?

Thanks

Nov 12 '05 #2

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

Similar topics

0
1368
by: Andy Fish | last post by:
Hi, I have server-based Java application that maintains a fairly large XML structure as a DOM. In response to a user request I want to select various nodes (including sub-nodes) and jam them...
1
3632
by: Casper B | last post by:
As the topic says, I am wondering how (in Java) I can extract a sub-tree of a org.w3c.dom.Document and form a brand new one. I use Oracle's XMLDocument implementation and have been playing around...
0
1194
by: John Spiegel | last post by:
Hi all, I'm trying to efficiently pull data out of an xml file into a XmlDocument AND create another "sub" document based on one subtree of the document. For example, say I've got: <Books>...
2
6185
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 ...
7
4157
by: Mark | last post by:
Hi... A colleague just referred this question to me. He's getting an xml file from another party, which he's trying to process into another dom using an XmlTextReader and...
1
9621
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
4
18160
by: Jesper Stocholm | last post by:
I have a database class that maintains data about customers i my system. The basic XML for this looks like: <Chunk> <Vendor> <Database/> </Vendor> </Chunk> When a user is to be registrered...
4
1803
by: Carlos Albert | last post by:
Hello, Would you tell me if there is a way to extract a single node as a new xmldocument? Thanks.
2
1669
by: Martin Pöpping | last post by:
Hello, I want to add some elements of one XmlDocument in another. My code looks like this: XmlDocument docA= new XmlDocument(); docA.LoadXml(record); XmlNodeList nl =...
0
7076
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
7274
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,...
1
6984
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
7453
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...
0
5576
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
3162
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
1507
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 ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
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...

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.