Question

I'm going on a couple assumptions here:

  1. XPathDocument is not editable.
  2. XmlDocument is editable.
  3. XPathDocument is more efficient for XslCompiledTransform.

That being the case (and please correct me if I am wrong), would it be better (more efficient) to:

  1. Make modifications using the XmlDocument, then convert to an XPathDocument before the transform. Is there an optimized way to do this?
  2. Just stick with the XmlDocument through the transform.

Some background, I'm getting a complex xml from a webservice, then use xpath to find some elements which need to be modified, then use a xslt to create html.

Thanks in advance for the help.

Was it helpful?

Solution

It depends on how much modification is required, how big the data is, and whether you are familiar with xslt. If "not" to the last, just use XDocument etc (last time I ran a profile, XDocument was quicker than XmlDocument for my data - run your own tests). Use XDocument.Load / XDocument.Parse, find your node, edit it, and save it.


If you must use xslt, then XDocument isn't really an option; once you've loaded it into XmlDocument you might as well stay with XmlDocument - I would not recommend parsing it into a second DOM.

Of course, it makes we wonder: why modify the xml outside of xslt if you are going to use xslt; perhaps just translate during the xslt?

To get a 100% accurate answer for your data you'll need to profile it, of course. But things such as appropriate use of xslt grouping constructs will often make a much bigger difference than XmlDocument vs XPathDocument.

OTHER TIPS

Just use the XmlDocument class for the transform. It would have to be a massive document to really see a performance gain. You may want to compile a static instance of the XslCompiledTransform class if you plan on using it multiple times.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top