Project

Profile

Help

Support #4697

closed

How to get details on XML parsing error during stylesheet compilation in Saxon 10.2 .NET

Added by Martin Honnen over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Low
Category:
s9api API
Sprint/Milestone:
-
Start date:
2020-08-26
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, trunk
Fix Committed on Branch:
10, trunk
Fixed in Maintenance Release:
Platforms:

Description

While trying to integrate Saxon 10.2 .NET HE I have found that any errors reported by the XML parser during stylesheet compilation lack specific details given by the XML parser that are present in 9.9.1.7 HE.

Example:

           Processor processor = new Processor();

            XsltCompiler xsltCompiler = processor.NewXsltCompiler();

            xsltCompiler.SetErrorList(new List<XmlProcessingError>());

            string xslt = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""3.0""</xsl:stylesheet>";

            XsltExecutable xsltExecutable;

            using (StringReader xsltReader = new StringReader(xslt))
            {
                try
                {
                    xsltExecutable = xsltCompiler.Compile(xsltReader);
                }
                catch (Exception)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat("Stylesheet compilation failed with {0} error(s):", xsltCompiler.GetErrorList().Count);
                    sb.AppendLine();
                    int errCount = 0;
                    foreach (var error in xsltCompiler.GetErrorList())
                    {
                        errCount++;
                        string message;
                        try
                        {
                            message = error.InnerMessage;
                        }
                        catch (NullReferenceException)
                        {
                            message = error.Message;
                        }

                        sb.AppendFormat("Error {0} at line {1}:{2} : {3}", errCount, error.LineNumber, error.ColumnNumber, message);
                        sb.AppendLine();
                    }
                    Console.WriteLine(sb.ToString());
                }
            }

with Saxon 10 only gives the general error 

Stylesheet compilation failed with 1 error(s): Error 1 at line 1:79 : Error reported by XML parser

while the previous code for Saxon 9.9

            Processor processor = new Processor();

            XsltCompiler xsltCompiler = processor.NewXsltCompiler();

            xsltCompiler.ErrorList = new List<StaticError>();

            string xslt = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""3.0""</xsl:stylesheet>";

            XsltExecutable xsltExecutable;
            
            using (StringReader xsltReader = new StringReader(xslt))
            {
                try
                {
                    xsltExecutable = xsltCompiler.Compile(xsltReader);
                }
                catch (Exception)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat("Stylesheet compilation failed with {0} error(s):", xsltCompiler.ErrorList.Count);
                    sb.AppendLine();
                    int errCount = 0;
                    foreach (StaticError error in xsltCompiler.ErrorList)
                    {
                        errCount++;
                        string message;
                        try
                        {
                            message = error.InnerMessage;
                        }
                        catch (NullReferenceException)
                        {
                            message = error.Message;
                        }
                        sb.AppendFormat("Error {0} at line {1}:{2} : {3}", errCount, error.LineNumber, error.ColumnNumber, message);
                        sb.AppendLine();
                    }
                    Console.WriteLine(sb.ToString());
                }
            }

outputs

Stylesheet compilation failed with 1 error(s):
Error 1 at line 1:79 : Error reported by XML parser: Element type "xsl:stylesheet" must be followed by either attribute specifications, ">" or "/>".

i.e. has the precise message from the XML parser.

Is there any way to get that precise message raised by the XML parser in Saxon 10.2 .NET as well?

Please register to edit this issue

Also available in: Atom PDF