Project

Profile

Help

Result document output .NET Saxon 10.6

Added by Matt Van Voorhies almost 2 years ago

Hey folks, we're close to moving our Saxon based transformation code to production and one of the remaining items that's nagging at us is the output via result-document lacks the XML declaration.

Saxon EE 10.6, .NET

When we do a direct transform, the output is beautiful, spacing (which is vital to us) is accurate, everything looks great, there IS an XML declaration or none based on the output "omit-xml-declaration" attribute value.

The output from the result-document operation however lacks the xml declaration and I can't seem to get it to display despite a few awkward attempts to adjust the XSL with the same attribute. (It is beautifully spaced and otherwise mimics the direct transform.

We use an implementation of IResultDocumentHandler and get the output files.

The IResultDocumentHandler code is pretty basic and we retrieve the output via:

XmlOutput = ((XdmDestination) xmlDocumentResultsHT[fileNameResultsKey])?.XdmNode?.OuterXml;

That gets us the output files using the key (which is the filename) and the XML as a string (XmlOutput). I suspect I'm not doing this correctly, but I can't find any reference other than this. It's important that we maintain the filenames as much of our XML processing/transformation is used in an automated fashion. The lack of XML declaration is -- so far -- not show stopping, but I figured somebody here could assist me in figuring out what I might be doing incorrectly to obtain the XML WITH the xml declaration.

Any thoughts? Thanks in advance.


Replies (4)

Please register to reply

RE: Result document output .NET Saxon 10.6 - Added by Michael Kay almost 2 years ago

The .OuterXml property is serialising the XdmNode containing the result document with default serialization properties including omit-xml-declaration="yes".

I would suggest returning a Serializer from your IResultDocumentHandler rather than an XdmDestination; that will give you full control over serialization options. Alternatively, if you really want the result as an XdmNode, you can control how it is serialized by creating a serializer using Processor.NewSerializer(), setting the serialization properties required, and then calling Serializer.SerializeXdmNode()

RE: Result document output .NET Saxon 10.6 - Added by Matt Van Voorhies almost 2 years ago

Thanks Michael,

I tried to experiment with the recommendation to return a serialized instead of an xdmdestination but couldn't get that to work -- could I trouble you for a basic example of what that would look like?

RE: Result document output .NET Saxon 10.6 - Added by Michael Kay almost 2 years ago

Something like

class MyResultHandler : IResultHandler {

   public MyResultHandler(Processor proc) {
      Processor proc = proc;
   }

   public override XmlDestination HandleResultDocument (string href, Uri baseUri) {
         StringWriter sw = new StringWriter():
         Serializer s = proc.NewSerializer(sw);
         s.SetOutputProperty(...., ....);
         string resultKey = key(href, baseUri);
         resultDocumentIndex[resultKey] = sw;
         return s;
   }
}

and then on completion use resultDocumentIndex[resultKey].ToString() to access the serialized content.

RE: Result document output .NET Saxon 10.6 - Added by Matt Van Voorhies almost 2 years ago

Fantastic!!! That is working for me - thank you!!!

    (1-4/4)

    Please register to reply