I'm going on a couple assumptions here:
- XPathDocument is not editable.
- XmlDocument is editable.
- 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:
- Make modifications using the XmlDocument, then convert to an XPathDocument before the transform. Is there an optimized way to do this?
- 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.
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 thanXmlDocument
for my data - run your own tests). UseXDocument.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 intoXmlDocument
you might as well stay withXmlDocument
- 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
vsXPathDocument
.