When strings with unicode characters are stored in a StyledLayerDescriptor, e.g. as the name of a rule, the resulting XML representation created by GeoTools is not valid when read by a SAX Parser, e.g. in GeoTools. Unicode characters in a string such as \u001a get written out as When reading the string back in, a org.xml.sax.SAXParseException is raised. Changing the XML header from <?xml version="1.0" encoding="UTF-8"?> to <?xml version="1.1" encoding="UTF-8"?> causes the SLD file to be parsed successfully. The solutions are:
- The XML string generated when encoding an Styled Layer Descriptor needs to be compliant with XML version 1.0
- The org.geotools.styling.SLDTransformer class or the classes it uses need to be aware of unicode characters and change the XML version to 1.1.
- Set the XML version to 1.1 regardless.
Test class attached to illustrate the error and solution. |