我正在编写一个带有this教程的XML文件。我申请了
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "4");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
xml formetting的代码。
但对于长xml数据,它显示xml像khis:
<kml>
<Placemark>
<name>yong</name>
<Polygon>
<timezone>EASTERN</timezone>
<outerBoundaryIs>
<LinearRing>
<coordinates>-77.05788457660967,38.87253259892824,100
-77.05465973756702,38.87291016281703,100
-77.05315536854791,38.87053267794386,100
-77.05552622493516,38.868757801256,100
-77.05844056290393,38.86996206506943,100
-77.05788457660967,38.87253259892824,100</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</kml>
但我想以下列方式格式化:
<kml>
<Placemark>
<name>yong</name>
<Polygon>
<timezone>EASTERN</timezone>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-77.05788457660967,38.87253259892824,100
-77.05465973756702,38.87291016281703,100
-77.05315536854791,38.87053267794386,100
-77.05552622493516,38.868757801256,100
-77.05844056290393,38.86996206506943,100
-77.05788457660967,38.87253259892824,100
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</kml>
怎么做?是否可以实现变压器中的任何方式或其他属性? 提前谢谢..
答案 0 :(得分:0)
我不知道这是否可行。
我认为你的字段坐标是一个字符串。 Transformer确实修改了String的内容,以防止例如更改.String是一个空格,制表符和换行符有意义的文本。
如果您需要将此字段对齐,您可以: