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
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
[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