日期:2014-05-20  浏览次数:20745 次

关于生产的XML里有回车的问题

只是代码的一部分,不过足以说明问题,望专家指教。

import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
Properties properties = transformer.getOutputProperties();

properties.setProperty(OutputKeys.ENCODING,"gb2312");
properties.setProperty(OutputKeys.METHOD,"xml");
properties.setProperty(OutputKeys.INDENT,"yes");

transformer.setOutputProperties(properties);

StringWriter sw = new StringWriter();
DOMSource source = new DOMSource(document);//document是我已经设置好值得Document对象
StreamResult result = new StreamResult(sw);
transformer.transform(source,result);



====================================================================

问题在于生成的XMl有点问题

下面的是生成的一部分
+/v7+Pj4+Pj4+Pj4+Pj4+Pj4+fn5+fn5+fn5
+fn5+Pj4+Pj4+Pj4+Pj4+Pj4+fn5+Pj4+Pj49/f3+Pj4+fn5+Pj4+fn5+fn5+Pj4+Pj4+Pj4+Pj4
+Pj4+fn5+Pn4+fj5+fj5+Pj49/f4+Pj4+fn5+fn5+fn5+fn5+Pj49/f3+Pj4+fn5+Pj4+Pj4+fn5
+fn59/f3+Pj4+Pj4+Pj4+Pj4+Pj4+fn5+Pj49/f3+Pj4+Pj4+fn5+fn5+fn5+Pj4+fn5+Pj4+Pj4
+fn5+Pj4+Pj4+Pj4+fn5+Pj4+Pj4+Pj4+fn5+fn5+fn5+fn5+Pj4+Pj4+Pj4+fn5+Pj4+Pj4+fn5



而我想要的是这个效果(不要那些&#13)

+/v7+Pj4+Pj4+Pj4+Pj4+Pj4+fn5+fn5+fn5
+fn5+Pj4+Pj4+Pj4+Pj4+Pj4+fn5+Pj4+Pj49/f3+Pj4+fn5+Pj4+fn5+fn5+Pj4+Pj4+Pj4+Pj4
+Pj4+fn5+Pn4+fj5+fj5+Pj49/f4+Pj4+fn5+fn5+fn5+fn5+Pj49/f3+Pj4+fn5+Pj4+Pj4+fn5
+fn59/f3+Pj4+Pj4+Pj4+Pj4+Pj4+fn5+Pj49/f3+Pj4+Pj4+fn5+fn5+fn5+Pj4+fn5+Pj4+Pj4
+fn5+Pj4+Pj4+Pj4+fn5+Pj4+Pj4+Pj4+fn5+fn5+fn5+fn5+Pj4+Pj4+Pj4+fn5+Pj4+Pj4+fn5



------解决方案--------------------

------解决方案--------------------

------解决方案--------------------
用filter吧....
------解决方案--------------------
呵呵,楼主可以用楼上的建议,用过滤,先用system来打印出来测试一下就可以用了.过滤掉你不想要的.