.net - XSL Transformation through code does not result in the same output as XSL transformation done through a tool -


I am

I turned to the other XML files using Aksmelaksmeted Transform classes for your XML file. NET Framework 3.5

This is my code.

  private static void change (string sXmlPath, string sXslPath, string Autputfailnam) {{XPathDocument myXPathDoc = new XPathDocument (sXmlPath)} XslCompiledTransform myXslTrans = new XslCompiledTransform (); // Load myXslTrans.Load xls (sXslPath); // Create output stream XmlTextWriter myWriter = new XmlTextWriter (outputFileName, null); // Xml myXslTrans.Transform (myXPathDoc, blank, myWriter); MyWriter.Close (); } Hold (exception e) {EventLogger eventLog; EventLog = New Event Logger ("Transform Ulyet", E. Toaster ()); }}}  

The code works, but the output file does not have XML declaration in header.

  **  

I am hurt to understand this. When I change the XML using the same XSL file, Notepad ++ or the XML declaration header changes when you use Visual Studio's tools. So what XslCompiledTransform is responsible for reducing this announcement? I'm surprised.

Anyone facing similar issues?

My XSL file title looks like this.

  & lt ;? Xml version = "1.0" encoding = "ISO-8859-1" & gt; & Lt; Xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" & gt; & Lt; Xsl: output method = "xml" version = "1.0" encoding = "UTF-8" indent = "yes" /> & Lt; Xsl: template match = "/" & gt;  

XML author uses no settings associated with it.

Change

// output stream Aksmeltadwartr Mairvetr = new Aksmeltadwartr (Autputfailnam, null);

from

  XmlWriterSettings settings = new XmlWriterSettings {OmitXmlDeclaration = false}; XmlWriter myWriter = XmlWriter.Create (OutputFilename, Settings); Alternatively, you can reduce the transformation setup:  
  make private static zero changes (string sxmlpath, string sxslpath , String outputFileName) {try {XslCompiledTransform xsl = New XslCompiledTransform (); // Load XSL xsl.load (sXslPath); // XML Document XSL Transform (sXmlPath, outputFileName) conversion; } Hold (exception e) {// handle exception}}  

This should also respect the instructions from the XSLT file, especially omit-xml-declaration attribute, for which the default value is "no" if not specified.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -