Page 1 of 1

Runtime Errors from parse-xml not catched

Posted: Wed Aug 12, 2015 8:35 am
by fsteimke
Hi,
i have to parse strings with escaped markup, contained in the @body attribute of an ownedComment Element. An example woud be @body='<p>test</p>'

In order to deal with parser errors, which could be caused by typos in the string above, i'd like to use the new try/catch mechanism of XSLT 3.

So i wrote something along these lines:

Code: Select all


<xsl:try>
<xsl:variable name="doc" as="document-node()" select="parse-xml-fragment(db:escapeEntities($string))"/>
<xsl:apply-templates select="$doc/*" mode="db-ns"/>
<xsl:catch>
<db:para>ERROR</db:para>
</xsl:catch>
</xsl:try>
Everything works fine as long as the input can be parsed without errors. But if it is not well-formed, or if it contains references to undeclared entities, the runtime error is not catched. I would like to get the DocBook para Element with error as content, but instead the transformation fails with an error message from saxon which tells me, why the string cannot be parsed.

This is a bug, isn't it?

Oxygen 17.0, build 2015051321 on Windows 7 64 bit with Saxon EE 9.6.0.5. Stylesheet Version is 3.0.

Sincerely,
Frank

Re: Runtime Errors from parse-xml not catched

Posted: Wed Aug 12, 2015 11:37 am
by radu_pisoi
Hi,

I have tried to reproduce the problem by running the transformation with Saxon EE 9.6.0.5 from the command line. In this case, the transformation behavior is the expected one. If the document to be parsed is not wellformed then the result of the try instruction is given by the evaluation of the catch clause.

So, this seems to be an oXygen specific issue that comes from the interaction between oXygen and the Saxon processor.
I will register it to our issue tracking system to be resolved in a future oXygen version.

Re: Runtime Errors from parse-xml not catched

Posted: Fri Aug 28, 2015 10:30 pm
by dsewell
There is a similar problem with XQuery and fn:parse-xml():

Code: Select all

xquery version "3.0";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:omit-xml-declaration "true";

try {
let $xml-string := '<para>Paragraph</p>'
return parse-xml($xml-string)
}
catch * {
<error>{$err:code}</error>
}
If you run that with standalone Saxon 9.6.0.7, the output is
<error>err:FODC0006</error>
and a message is sent to standard error
SXXP0003: Error reported by XML parser: The element type "para" must be terminated by the
matching end-tag "</para>".
If I run the code in oXygen, I get only the "Transformation problems" message reporting "Error reported by XML parser", but there is no output from the transformation.

I hope that behavior can be fixed -- I also need to use fn:parse-xml() with try/catch in order to find bad quoted HTML that looks like my variable above.

Re: Runtime Errors from parse-xml not catched

Posted: Mon Aug 31, 2015 10:29 am
by radu_pisoi
Hi,

Yes, it seems to be a similar problem. The transformation execution should not be stopped when an dynamic error is caught by try/catch instruction.

I will also register this case in our issue tracking system.

Re: Runtime Errors from parse-xml not catched

Posted: Fri Oct 28, 2016 11:44 am
by Radu
Hi,

Just to update this thread, the issue should be fixed in Oxygen 18.1 which we released a couple of weeks ago.

Regards,
Radu

Re: Runtime Errors from parse-xml not catched

Posted: Fri Oct 28, 2016 4:56 pm
by dsewell
Excellent, thanks for the update and the fix.