我有一个Map键/值:字符串/字符串,其中包含一个XML元素名称作为键,一个大的XML嵌套字符串作为值,例如:
Map<String, String> obj;
INSPIRE => <oi-cov:OrthoimageCoverageMetadata xmlns:oi-cov="http://inspire.ec.europa.eu/schemas/oi/4.0" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:base="http://inspire.ec.europa.eu/schemas/base/3.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://inspire.ec.europa.eu/schemas/oi/4.0 https://schema.datacove.eu/OrthoimageryMetadata.xsd"> <oi-cov:inspireId> ...
使用 Jackson 将此对象序列化为String,映射值中的XML特殊字符'<'和'>'总是转换为'&lt; '和“&gt;” 。 如何预防?
private static final XmlMapper xmlMapper = new XmlMapper();
String xml = xmlMapper.writer().writeValueAsString(obj);
当前输出为字符串:
<INSPIRE><oi-cov:OrthoimageCoverageMetadata xmlns:oi-cov="http://inspire.ec.europa.eu/schemas/oi/4.0" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:base="http://inspire.ec.europa.eu/schemas/base/3.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://inspire.ec.europa.eu/schemas/oi/4.0 https://schema.datacove.eu/OrthoimageryMetadata.xsd">
<oi-cov:inspireId>
<base:Identifier>