Re: parse-xml-fragment() Fails in Saxon 9.5 but not in 9.8

Michael Kay <[email protected]> Fri, 15 Jan 2021 23:36:00 +0000
Newsgroups gmane.text.xml.saxon.help
Message-ID <[email protected]>
There have been a few issues over the years in supporting parse-xml-fragment() because XML parsers don't generally support this functionality "out of the box". The approach we use is to parse a dummy document that refers to the supplied string as an external entity; to achieve that we need to set an entity resolver on the parser, and that's where the problems start coming in. Some implementations of XMLReader, for example one supplied by a CatalogResolver, ignore requests to setEntityResolver(), so we need a parser that we know will respect a call on setEntityResolver(). We can do that in JDK 9 using SAXParserFactory.newDefaultInstance(), but on JDK 8 it's more complex.  And of course Saxon 9.5 came out long before any of these things.

In some ways it would be easier to wrap the supplied document in a wrapper element, but the edge cases get difficult: the declaration that can appear in an external parsed entity is not the same as the declaration on a document entity.

There's a price for not moving forward...

Michael Kay
Saxonica

> On 15 Jan 2021, at 17:03, Eliot Kimber <[email protected]> wrote:
> 
> I realize this is another "help me with a version you never want to think about again question" but I have to ask it.
> 
> Per my recent post on the XSLT list, I'm using saxon:parse-pseudo-attribute() function to get the value of an Oxygen delete PI @content attribute, which contains escaped XML markup.
> 
> Using this code:
> 
> <xsl:variable name="rawMarkup" as="xs:string" select="saxon:parse-pseudo-attribute('content')"/>
> <xsl:variable name="deletedMarkup" as="element">
>  <deletedMarkup xmlns="">
>   <xsl:sequence select="parse-xml-fragment($rawMarkup)"/>
>  </deletedMarkup>
> </xsl:variable>
> 
> <xsl:apply-templates select="$deletedMarkup" mode="handle-deleted-markup"/>
> 
> it works perfectly with Saxon 9.8.
> 
> However, with Saxon 9.5 I get these errors:
> 
> Error reported by XML parser processing
> file:/home/kimberw/workspace/nbs/src/xslt/gaonb-pe/preProcessPhase.xsl: Scanner State 24
> not Recognized
> Error on line 109 of preProcessPhase.xsl:
> FODC0006: First argument to parse-xml-fragment() is not a well-formed and
> namespace-well-formed XML fragment. XML parser reported: Error reported by XML parser
> 
> With Saxon 9.5 I can write the value of $rawMarkup to a file and see that it is in fact well-formed XML, but of course there's no way that Oxygen would not put well-formed XML here.
> 
> Given that Saxon 9.5 is required for this application, any idea if there's any workaround for this particular error?
> 
> The requirement is to take the value of the @content attribute and process it as XML in the context of the current transform. Because this transform is run inside a larger system, doing some kind of file-level preprocessing is not really an option, at least not one that could be easily applied.
> 
> Thanks,
> 
> Eliot
> --
> Eliot Kimber
> http://contrext.com
> 
> 
> 
> 
> 
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help



_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help