Java Code Examples for org.dom4j.Document#getXMLEncoding()
The following examples show how to use
org.dom4j.Document#getXMLEncoding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Identity.java From hermes with Apache License 2.0 | 6 votes |
private static Document creXmlDoc(String xmlStr) { if (Strings.empty(xmlStr)) { throw new RuntimeException("参数不能为空"); } SAXReader saxReader = new SAXReader(); Document document = null; try { document = saxReader.read(new ByteArrayInputStream(xmlStr.getBytes("UTF-8"))); Element rootElement = document.getRootElement(); String getXMLEncoding = document.getXMLEncoding(); String rootname = rootElement.getName(); System.out.println("getXMLEncoding>>>" + getXMLEncoding + ",rootname>>>" + rootname); OutputFormat format = OutputFormat.createPrettyPrint(); /** 指定XML字符集编码 */ format.setEncoding("UTF-8"); Logger.info(xmlStr); } catch (Exception e) { e.printStackTrace(); } return document; }