The error "Content not allowed in prolog" is sometimes caused by the presence of a byte-order-mark when not expected. I suspect that could be the situation here.
 
I won't be in a position to investigate this in detail until I'm back from vacation. But you could try forcing it to use the microsoft XML parser rather than the Xerces parser, which is now the default.
 
Michael Kay
Saxonica


From: Vincent Lambert [mailto:vlamber1@matrox.com]
Sent: 02 September 2009 20:22
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Saxon .Net Content is not allowed in prolog

Hello,

I am currently using saxon.Net 9.2 for a project. I try to apply 2 different stylesheets to a document and then save the output.

Here is the transformation code.
                        // Load xmlDoc with a string containing the xml document.

                        Processor proc = new Processor();
                XsltCompiler comp = proc.NewXsltCompiler();
                FileStream stylesheetFileStream = new FileStream(self.GetRaw<string>("stylesheet"), FileMode.Open, FileAccess.Read);

                comp.BaseUri = new Uri(self.GetRaw<string>("stylesheet"));
                comp.ErrorList = new System.Collections.ArrayList();
                try
                {
                    exec = comp.Compile(stylesheetFileStream);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    stylesheetFileStream.Close();
                }
                XsltTransformer transf = exec.Load();
                MemoryStream mstream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xmlDoc), true);
                transf.SetInputStream(mstream, new Uri(self.GetRaw<string>("stylesheet")));

                StringWriter strWriter = new StringWriter();
                XmlTextWriter xtw = new XmlTextWriter(strWriter);
                TextWriterDestination dest = new TextWriterDestination(xtw);
                transf.Run(dest);

This code is inside a method that is called twice and set the xmlDoc variable to result of the previous call.

When I run it, I get a "Content is not allowed in prolog." exception although my file seems valid. (I can apply the two stylesheets using the saxon executable.);

Here is the beginning of the result of the first transformation (the crash occurs at the second):

<?xml version="1.0" encoding="utf-16"?><html xmlns:ms="urn:anything" xmlns:MSHelp="http://msdn.microsoft.com/msHelp" xml:lang="en" lang="en"><head><title>MappGetError</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="xml-files-root" content="../../" /><meta name="manual-name" content="MIL-command-reference" /><meta name="manual-version" content="" /><meta name="generation-time" content="~generation-time~" /><meta name="xml-timestamp" content="~xml-timestamp~" /><link id="staticCSS" href="../../CSS Files/Matrox.Imaging.Common.css" rel="stylesheet" type="text/css" /><script language="JavaScript" src="../../JS Files/jquery-1.2.6.min.js" /><script language="JavaScript" src="../../JS Files/Matrox.Imaging.Utils.js" /><script language="JavaScript" src="../../JS Files/Matrox.Imaging.AbstractEventModel.js" /><script language="JavaScript" src="../../JS Files/Matrox.Imaging.Menu.js" /><script language="JavaScript" src="../../JS Files/Matrox.Imaging.Common.js" /></head><script type="text/javascript">

    Controller.singleton().supportedBoards = [
   
    ];
   
    try{
    preInit();
  …

It is a bit messy, but there is nothing in the prolog except the xml declaration.

Thank you for your help.
-----------------------------------------------------
Vincent Lambert
XML Programmer
Matrox Imaging