Re: Invalid byte 2 of 4-byte UTF-8 sequence

Alan Painter <[email protected]> Thu, 10 Dec 2020 16:45:02 +0100
Newsgroups gmane.text.xml.saxon.help
Message-ID <CAN+GtW3LmB91-ej-SVnP-=sy62DUoU+3Ahy5fr6vRiS6QF-LvA@mail.gmail.com>
Hey Matthew,

I typically see this sort of problem when reading documents (probably
files) that contain unicode chars into a Java string and then using the
Java "String" class as the source document for the transformation.  A
better approach is to use a "SourceStream" as the source of the
transformation, which then allows the source document to be parsed as bytes.

That's an example of one place where you might see this sort of UTF-8 error.

If you do have more details about how you are presenting your source
document for the transformation, it would be easier to determine at what
point the problem occurs.

I've loaded your example into Martin's excellent online XSLT and you'll see
that it manages the unicode chars without any trouble.

https://martin-honnen.github.io/xslt3fiddle/?xslt=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0D%0A%3Cxsl%3Astylesheet+xmlns%3Axsl%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2FXSL%2FTransform%22%0D%0A++version%3D%223.0%22%0D%0A++xmlns%3Axs%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%3E%0D%0A++%0D%0A++%3Cxsl%3Aoutput+method%3D%22text%22+%2F%3E%0D%0A%0D%0A++%3Cxsl%3Amode+on-no-match%3D%22shallow-copy%22%2F%3E%0D%0A%0D%0A++%3Cxsl%3Atemplate+match%3D%22%2F%22+%3E%0D%0A++++%3Cxsl%3Afor-each+select%3D%22example%22%3E%0D%0A++++++%3Cxsl%3Avalue-of+select%3D%22%27Title%3A+++++++++%27+%7C%7C+Title%22+%2F%3E%0D%0A++++++%3Cxsl%3Avalue-of+select%3D%22%27%26%23xA%3B%27%22++++++++++++++++++++%2F%3E%0D%0A++++++%3Cxsl%3Avalue-of+select%3D%22%27Place_Keyword%3A+%27+%7C%7C+Place_Keyword%22+%2F%3E%0D%0A++++%3C%2Fxsl%3Afor-each%3E%0D%0A++%3C%2Fxsl%3Atemplate%3E%0D%0A++%0D%0A%3C%2Fxsl%3Astylesheet%3E%0D%0A&input=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0D%0A%3Cexample%3E%0D%0A++%3CTitle%3ETIGER%2FLine+Shapefile%2C+2020%2C++county%2C+Bayam%C3%B3n+Municipio%2C+PR%2C+Area+Landmark+County-based+Shapefile+%3C%2FTitle%3E+++++++++++++++++++++++++++++++%0D%0A++%3CPlace_Keyword%3EBayam%C3%B3n%3C%2FPlace_Keyword%3E%0D%0A%3C%2Fexample%3E%0D%0A%0D%0A&input-type=XML

good luck in any case and best regards

On Thu, Dec 10, 2020 at 4:02 PM Matthew J McCready (CENSUS/GEO FED) via
saxon-help <[email protected]> wrote:

> Fellow Saxonica Users,
>
> When the processor tries to handle the following elements:
>
>       <Title>TIGER/Line Shapefile, 2020,  county, Bayamón Municipio, PR,
> Area Landmark County-based Shapefile </Title>
>
> <Place_Keyword>Bayamón</Place_Keyword>
>
> It gets the following error:
>
> Invalid byte 2 of 4-byte UTF-8 sequence
>
> Any idea why this would be happening?
>
> Thanks
>
>
> *Matthew McCready*
> U.S Census Bureau
> Geography Division
> Geographic Standards, Criteria, and Quality Branch (GSCQB)
> 4H160B
> 301-763-9101
> http://www.census.gov/
> http://www.census.gov/about/contact-us/social_media.html
>
> _______________________________________________
> 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