Saxon.Net -- How can i get all tracing information and result doc information when using "processor.SetProperty("http://saxon.sf.net/feature/timing", "true"); " -- not setting SetOutputWriter() to Console.Out

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Saxon.Net -- How can i get all tracing information and result doc information when using "processor.SetProperty("http://saxon.sf.net/feature/timing", "true"); " -- not setting SetOutputWriter() to Console.Out

Wintermann, John (RTIS)

Hi,

I’ve noticed that when I run XsltMultipleOutput from ExamplesEE.cs on the command line, the serializer.SetOutputWriter(Console.Out); provides me with the timing information and basic tracing information like names of output files when using xsl:result-document

 

E.g.,

===== XsltMultipleOutput =======

 

Using parser org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser

Building tree for file:///C:/SaxTestSamples/samples/data/11111111_A.xml using class net.sf.saxon.tree.tiny.TinyBuilder

Tree built in 266.720742ms

Tree size: 2105 nodes, 32455 characters, 1091 attributes

<sup xmlns="http://www.w3.org/1999/xhtml" title="(data)">(P)</sup>

Writing to file:/C:/SaxTest/SaxTest/bin/Debug/test_1.xml

Writing to file:/C:/SaxTest/SaxTest/bin/Debug/test_2.xml

Writing to file:/C:/SaxTest/SaxTest/bin/Debug/test_3.xml

 

 

However, if I’m not using a console application and I have the following statements in my code,

 

Processor xslProcessor = new Processor(licensedEdition:true);

xslProcessor.SetProperty("http://saxon.sf.net/feature/preferJaxpParser", "true");

xslProcessor.SetProperty("http://saxon.sf.net/feature/timing", "true");

 

// Create a compiler

XsltCompiler compiler = xslProcessor.NewXsltCompiler();

 

// Create a list to hold the error information

compiler.ErrorList = new ArrayList();

 

try

{               

 

// Load the source document

XdmNode input = xslProcessor.NewDocumentBuilder().Build(new Uri(sourceUri));

 

 

//compile the stylesheet

XsltExecutable exec = compiler.Compile(new Uri(xslUri));

 

..... more code ...

 

StringWriter sw = new StringWriter();                   

serializer.SetOutputWriter(sw);                  

//serializer.SetOutputWriter(Console.Out);                 

transformer.Run(serializer);

xslOutMsgs.Add(sw.ToString());

 

the xsl:result-doc files are produced but the value of string sw.ToString();  includes only the xml markup that I have intentionally not delivered to the result documents:

“<sup xmlns="http://www.w3.org/1999/xhtml" title="(data)">(P)</sup>”

 

Is there a way for me to get sw.ToString() to include the timing and tracing information as if I would have run the application from the command line like in XsltMultipleOutput above?

 

Any advice will be greatly appreciated.

 

Thanks,

 

John

 

 

 


------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: Saxon.Net -- How can i get all tracing information and result doc information when using "processor.SetProperty("http://saxon.sf.net/feature/timing", "true"); " -- not setting SetOutputWriter() to Console.Out

Michael Kay

On 3 Dec 2015, at 05:14, Wintermann, John (RTIS) <[hidden email]> wrote:

Hi,

I’ve noticed that when I run XsltMultipleOutput from ExamplesEE.cs on the command line, the serializer.SetOutputWriter(Console.Out); provides me with the timing information and basic tracing information like names of output files when using xsl:result-document

 

E.g.,

===== XsltMultipleOutput =======

 

Using parser org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser

Building tree for file:///C:/SaxTestSamples/samples/data/11111111_A.xml using class net.sf.saxon.tree.tiny.TinyBuilder

Tree built in 266.720742ms

Tree size: 2105 nodes, 32455 characters, 1091 attributes

<sup xmlns="http://www.w3.org/1999/xhtml" title="(data)">(P)</sup>

Writing to file:/C:/SaxTest/SaxTest/bin/Debug/test_1.xml

Writing to file:/C:/SaxTest/SaxTest/bin/Debug/test_2.xml

Writing to file:/C:/SaxTest/SaxTest/bin/Debug/test_3.xml

 



What is actually happening here is that the query result (the <sup/> element) is written to System.out, and the messages are written to System.err, and both these output streams are displayed interleaved on the console. With some environments you'll see a distinction between the two output streams, e.g. the messages are in different colours.

 

However, if I’m not using a console application and I have the following statements in my code,

 

Processor xslProcessor = new Processor(licensedEdition:true);

xslProcessor.SetProperty("http://saxon.sf.net/feature/preferJaxpParser", "true");

xslProcessor.SetProperty("http://saxon.sf.net/feature/timing", "true");

 

// Create a compiler

XsltCompiler compiler = xslProcessor.NewXsltCompiler();

 

// Create a list to hold the error information

compiler.ErrorList = new ArrayList();

 

try

{               

 

// Load the source document

XdmNode input = xslProcessor.NewDocumentBuilder().Build(new Uri(sourceUri));

 

 

//compile the stylesheet

XsltExecutable exec = compiler.Compile(new Uri(xslUri));

 

..... more code ...

 

StringWriter sw = new StringWriter();                   

serializer.SetOutputWriter(sw);                  

//serializer.SetOutputWriter(Console.Out);                 

transformer.Run(serializer);

xslOutMsgs.Add(sw.ToString());

 

the xsl:result-doc files are produced but the value of string sw.ToString();  includes only the xml markup that I have intentionally not delivered to the result documents:

“<sup xmlns="http://www.w3.org/1999/xhtml" title="(data)">(P)</sup>”

 

Is there a way for me to get sw.ToString() to include the timing and tracing information as if I would have run the application from the command line like in XsltMultipleOutput above?

 


You can set the destination for the trace messages, but you have to dive in a little bit deep to do it. First get the Configuration that underpins the Saxon.Api.Processor, as the value of the Implementation property. You're now into Java space, so you'll need to declare a dependency on the saxon9.dll assembly and perhaps some of the IKVMC assemblies containing the Java runtime library; you'll need to use Java naming conventions (method names start with lower case); and you need to take care that methods are using Java types rather than C# types. But you can still write everything in C#. 

The Configuration class [1], has a method setLogger(), to which you can pass an instance of net.sf.saxon.lib.Logger [2]. Although that's defined as a Java abstract class, through the magic of IKVMC you can write your own subclass of Logger in C#. There are two abstract methods that you need to implement: asStreamResult() and println(). For the messages in your example output, just implement the println() method to send them wherever you want. The asStreamResult() method is used mainly for xsl:message output, and the simplest implementation is probably to return 

new javax.xml.transform.stream.StreamResult(java.lang.System.err) 

which will send xsl:message output to the console (if there is one!)

Michael Kay
Saxonica





------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help