久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Java、XML DocumentBuilder - 解析時設置編碼

Java, XML DocumentBuilder - setting the encoding when parsing(Java、XML DocumentBuilder - 解析時設置編碼)
本文介紹了Java、XML DocumentBuilder - 解析時設置編碼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試將保存 XML 文檔的樹(擴展 JTree)保存為已更改其結構的 DOM 對象.

I'm trying to save a tree (extends JTree) which holds an XML document to a DOM Object having changed it's structure.

我創建了一個新的文檔對象,遍歷樹成功檢索了內容(包括XML文檔的原始編碼),現在有了一個ByteArrayInputStream具有正確編碼的樹內容(XML 文檔).

I have created a new document object, traversed the tree to retrieve the contents successfully (including the original encoding of the XML document), and now have a ByteArrayInputStream which has the tree contents (XML document) with the correct encoding.

問題是當我解析 ByteArrayInputStream 時,編碼會自動更改為 UTF-8(在 XML 文檔中).

The problem is when I parse the ByteArrayInputStream the encoding is changed to UTF-8 (in the XML document) automatically.

有沒有辦法防止這種情況并使用 ByteArrayInputStream 中提供的正確編碼.

Is there a way to prevent this and use the correct encoding as provided in the ByteArrayInputStream.

值得補充的是,我已經使用了
transformer.setOutputProperty(OutputKeys.ENCODING, encoding) 方法來檢索正確的編碼.

It's also worth adding that I have already used the
transformer.setOutputProperty(OutputKeys.ENCODING, encoding) method to retrieve the right encoding.

任何幫助將不勝感激.

推薦答案

這是一個更新的答案,因為 OutputFormat 已被棄用:

Here's an updated answer since OutputFormat is deprecated :

TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");

StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(document), new StreamResult(writer));
String output = writer.getBuffer().toString().replaceAll("
|
", "");

第二部分將 XML 文檔作為字符串返回

The second part will return the XML Document as String

這篇關于Java、XML DocumentBuilder - 解析時設置編碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(Google 驅動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅動api服務賬戶查看上傳文件到谷歌驅動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 91原创视频 | 国内精品免费久久久久软件老师 | 在线观看免费黄色片 | 国产精品高清在线 | 国产成人综合亚洲欧美94在线 | 天天干b| 久久不射网 | 天天操夜夜爽 | 一级片子 | 婷婷99| 国产精品性做久久久久久 | 成人av一区二区在线观看 | www.日韩系列 | 四虎网站在线观看 | 精品视频在线免费观看 | 天天躁日日躁aaaa视频 | 国产一级毛片视频 | 中文字幕在线观看视频网站 | 一级毛片在线播放 | 黄色综合 | 日韩免费一区二区 | 毛片网站在线观看视频 | 不卡的av在线 | 中文字幕第5页 | 日韩精品久久久久 | 久久久涩 | 日韩精品一区二区在线 | 国产免费让你躁在线视频 | 亚洲精品欧美 | 国产高清视频在线播放 | 成人深夜福利在线观看 | 可以免费观看的av | 国产一区二区三区亚洲 | 欧美中文一区 | 成人二区| 久久不卡| 亚洲免费视频一区 | 亚洲人成一区二区三区性色 | 永久免费在线观看 | 亚洲免费一区二区 | 欧洲国产精品视频 |