java中使用html表情,将表情符号转换为HTML十进制代码或Unicode十六进制代码在java中...

I got the work around :

public static void htmlDecimalCodeGenerator() {

DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();

domFactory.setValidating(false);

// File inputFile = new File("/inputFile.xml");

File inputFile = new File("/inputFile.xml");

try {

FileOutputStream fop = null;

File OutFile = new File("/outputFile.xml");

fop = new FileOutputStream(OutFile);

DocumentBuilder builder = domFactory.newDocumentBuilder();

Document doc = builder.parse(inputFile);

TransformerFactory tf = TransformerFactory.newInstance();

Transformer transformer = tf.newTransformer();

/*

no value of OMIT_XML_DECLARATION will add following xml declaration in the beginning of the file.

*/

transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

/*

When the output method is "xml", the version value specifies the

version of XML to be used for outputting the result tree. The default

value for the xml output method is 1.0. When the output method is

"html", the version value indicates the version of the HTML.

The default value for the xml output method is 4.0, which specifies

that the result should be output as HTML conforming to the HTML 4.0

Recommendation [HTML]. If the output method is "text", the version

property is ignored

*/

transformer.setOutputProperty(OutputKeys.METHOD, "xml");

/*

Indent-- specifies whether the Transformer may

add additional whitespace when outputting the result tree; the value

must be yes or no.

*/

transformer.setOutputProperty(OutputKeys.INDENT, "no");

transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");

// transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

transformer.transform(new DOMSource(doc),

new StreamResult(new OutputStreamWriter(System.out, "UTF-8")));

// new StreamResult(new OutputStreamWriter(fop, "UTF-8")));

} catch (Exception e) {

e.printStackTrace();

}

}

}

2017-02-17 22:12:16

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值