Convert an XmlDocument to an XmlDocument using XSL
-
I've been using this code to produce a string representation of some xml that I output to a webpage:
XslCompiledTransform transform = new XslCompiledTransform(); transform.Load(XSL); StringWriter writer = new StringWriter(); transform.Transform(EMailDocument, null, writer); return xml = writer.ToString();
Now I need to change the code so that instead of a string I get back the output XmlDocument. My first attempt just to get things moving was to pump the output of the above into the LoadXml() method of the XmlDocument but I get errors about matching tags, I suspect because of the whitespace (\r\n etc) that is in the text. Does anyone have an easy way of transforming a document into another document? Cheers Russell -
I've been using this code to produce a string representation of some xml that I output to a webpage:
XslCompiledTransform transform = new XslCompiledTransform(); transform.Load(XSL); StringWriter writer = new StringWriter(); transform.Transform(EMailDocument, null, writer); return xml = writer.ToString();
Now I need to change the code so that instead of a string I get back the output XmlDocument. My first attempt just to get things moving was to pump the output of the above into the LoadXml() method of the XmlDocument but I get errors about matching tags, I suspect because of the whitespace (\r\n etc) that is in the text. Does anyone have an easy way of transforming a document into another document? Cheers RussellRussell Jones wrote:
Does anyone have an easy way of transforming a document into another document?
It's been a few years but there were methods that returned XmlSource or maybe XmlNode or some such thing in early versions of the BCL. However even if you use something like that with XSLT that is producing illegal XML ( Not well formed ), it will produce a similar error that LoadXML() does.
Russell Jones wrote:
but I get errors about matching tags
So I imagine you need to fix your XSLT either way. I've never tried it but if you set the XSLT output type to XML the XSLT processor might error and not even produce the string output.