2003-06-30 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Mon, 30 Jun 2003 17:01:25 +0000 (17:01 -0000)
committerZoltan Varga <vargaz@gmail.com>
Mon, 30 Jun 2003 17:01:25 +0000 (17:01 -0000)
* XslTransform.cs (GetStringFromDocument): Read the result using
xsltSaveResultToString, since the XML document returned by
applyStylesheet is missing the output processing done due to the
usage of the xsl:output directive.

svn path=/trunk/mcs/; revision=15770

mcs/class/System.XML/System.Xml.Xsl/ChangeLog
mcs/class/System.XML/System.Xml.Xsl/XslTransform.cs

index 31af02f5a2dcf8374bdc00da983e6ed8b1fa2e14..586614946738b4d88b96bc53a8d303bcfda86ea1 100644 (file)
@@ -1,3 +1,10 @@
+2003-06-30  Zoltan Varga  <vargaz@freemail.hu>
+
+       * XslTransform.cs (GetStringFromDocument): Read the result using
+       xsltSaveResultToString, since the XML document returned by
+       applyStylesheet is missing the output processing done due to the
+       usage of the xsl:output directive.
+
 2003-06-21  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
 
        * XslTransform.cs : Fixed Transform (string, string) not to call
index ff184cc51c8e5054d54b9ffb4426af1209d11f8a..b911afa07de984e6485c10363742b12b7ea52fd2 100644 (file)
@@ -183,12 +183,12 @@ namespace System.Xml.Xsl
                                resultDocument = ApplyStylesheet (xmlDocument, null, null);\r
 \r
                                /*\r
-                               * If I do this, the <?xml version=... is always present *\r
+                                * If I do this, the <?xml version=... is always present *\r
                                if (-1 == xsltSaveResultToFilename (outputfile, resultDocument, stylesheet, 0))\r
                                        throw new XmlException ("Error xsltSaveResultToFilename");\r
                                */\r
                                StreamWriter writer = new StreamWriter (new FileStream (outputfile, FileMode.Create));\r
-                               writer.Write (GetStringFromDocument (resultDocument));\r
+                               writer.Write (GetStringFromDocument (resultDocument, stylesheet));\r
                                writer.Close ();\r
                        } finally {\r
                                if (xmlDocument != IntPtr.Zero)\r
@@ -294,32 +294,25 @@ namespace System.Xml.Xsl
                        xmlCleanupParser ();\r
                }\r
 \r
-               static string GetStringFromDocument (IntPtr doc)\r
+               static string GetStringFromDocument (IntPtr doc, IntPtr stylesheet)\r
                {\r
                        IntPtr mem = IntPtr.Zero;\r
                        int size = 0;\r
-                       xmlDocDumpMemory (doc, ref mem, ref size);\r
-                       if (mem == IntPtr.Zero)\r
-                               throw new XmlException ("Error dumping document");\r
+\r
+                       int res = xsltSaveResultToString (ref mem, ref size, doc,\r
+                                                                                         stylesheet);\r
+                       if (res == -1)\r
+                               throw new XmlException ("xsltSaveResultToString () failed.");\r
 \r
                        string docStr = Marshal.PtrToStringAnsi (mem, size);\r
-                       // FIXME: Using xmlFree segfaults :-???\r
-                       //xmlFree (mem);\r
                        Marshal.FreeHGlobal (mem);\r
-                       //\r
-\r
-                       // Get rid of the <?xml...\r
-                       // FIXME: any other (faster) way that works?\r
-                       StringReader result = new StringReader (docStr);\r
-                       result.ReadLine (); // we want the semantics of line ending used here\r
-                       //\r
-                       return result.ReadToEnd ();\r
+                       return docStr;\r
                }\r
 \r
                string ApplyStylesheetAndGetString (IntPtr doc, string[] argArr, Hashtable extobjects)\r
                {\r
                        IntPtr xmlOutput = ApplyStylesheet (doc, argArr, extobjects);\r
-                       string strOutput = GetStringFromDocument (xmlOutput);\r
+                       string strOutput = GetStringFromDocument (xmlOutput, stylesheet);\r
                        xmlFreeDoc (xmlOutput);\r
 \r
                        return strOutput;\r
@@ -693,6 +686,10 @@ namespace System.Xml.Xsl
                [DllImport ("xslt")]\r
                static extern IntPtr xsltApplyStylesheet (IntPtr stylePtr, IntPtr DocPtr, string[] argPtr);\r
 \r
+               [DllImport ("xslt")]\r
+               static extern int xsltSaveResultToString (ref IntPtr stringPtr, ref int stringLen,\r
+                                                                                                 IntPtr docPtr, IntPtr stylePtr);\r
+\r
                [DllImport ("xslt")]\r
                static extern int xsltSaveResultToFilename (string URI, IntPtr doc, IntPtr styleSheet, int compression);\r
 \r