Project

Profile

Help

Bug #2002

XPathException was unhandled in .NET

Added by O'Neil Delpratt over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Category:
.NET API
Sprint/Milestone:
-
Start date:
2014-02-10
Due date:
% Done:

100%

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

Description

Reported by a Saxon user:

The following C#-Code always reports an 'XPathException was unhandled' with the message "The XML parser reported two validation errors" due a validation error in the XML parser. This should be caught by the Saxon .NET API and thrown as an .NET exception:

 public void Transform(string xmlPath, string xslPath, string outputPath)
        {

            FileStream outStream = null;
            Processor proc = null;
            XsltCompiler compiler = null;
            XsltTransformer transformer = null;
            XsltExecutable exec = null;

            IList errors = new ArrayList();

            try
            {
                outStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);

                proc = new Processor(true);

                proc.SetProperty("http://saxon.sf.net/feature/validation", "false");
                proc.SetProperty("http://saxon.sf.net/feature/dtd-validation-recoverable", "true");
                proc.SetProperty("http://saxon.sf.net/feature/validation-warnings", "true");

                //proc.SetProperty(FeatureKeys.SCHEMA_VALIDATION, "0"); => NOT WORKING

                XdmNode input = proc.NewDocumentBuilder().Build(new Uri(xmlPath));
                compiler = proc.NewXsltCompiler();
                compiler.ErrorList = errors;
                compiler.SchemaAware = false;

                exec = compiler.Compile(new Uri(xslPath));
                transformer = exec.Load();
                transformer.MessageListener = new UserMessageListener();

                transformer.InitialContextNode = input;

                Serializer serializer = new Serializer();
                serializer.SetOutputStream(outStream);
                transformer.Run(serializer);

                StringBuilder errorMessage = new StringBuilder();

                if (errors.Count > 0)
                    throw new ApplicationException(string.Join("\n", errors));
            }
            catch (StaticError se)
            {
                Console.WriteLine("Test failed with static error " + se.ErrorCode.LocalName + ": " + se.Message);
            }
            catch (DynamicError de)
            {
                Console.WriteLine("Test failed with dynamic error " + de.ErrorCode.LocalName + ": " + de.Message);
            }

            finally
            {
                if (outStream != null)
                    outStream.Close();

                outStream = null;
                transformer = null;
                exec = null;
                compiler = null;
                proc = null;
            }
        }

History

#1 Updated by O'Neil Delpratt over 7 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100

Big fixed and committed to subversion. Change made in the Configuration.cs to catch XPathException and throw as StaticError.

#2 Updated by O'Neil Delpratt over 7 years ago

  • Status changed from Resolved to Closed
  • Fixed in version set to 9.5.1.5

Bug fix applied in Saxon maintenance release 9.5.1.5

Please register to edit this issue

Also available in: Atom PDF