472,779 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

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 4277
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
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
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
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
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
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
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
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
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
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.