久久久久久久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 示例中缺少)
主站蜘蛛池模板: 久久五月婷 | 久草热播| 毛片一区二区三区 | 久久专区 | 欧美高清视频一区 | 天天操操操操操 | 国产精品久久久久久婷婷天堂 | 九色在线| 色婷婷综合久久久中文字幕 | 国产一区二区三区久久久久久久久 | 真人毛片| 九九在线视频 | 色综合99| 日韩成人在线播放 | 性精品 | 欧美一级小视频 | 81精品国产乱码久久久久久 | 日韩一区二区精品 | 欧美日韩专区 | 久久一级免费视频 | 精品欧美一区二区三区久久久 | 国产欧美日韩精品一区 | 日日摸夜夜添夜夜添特色大片 | 久久精品69 | 一区视频 | 成人国产精品入口免费视频 | 久久综合久久久 | 日韩一区三区 | 亚洲天堂精品一区 | 91精品中文字幕一区二区三区 | 久久精品97| 国产精品中文字幕一区二区三区 | 久久精品久久久 | 欧美二区三区 | 国产午夜一级 | 欧美在线视频a | 亚洲午夜久久久 | 国产网站在线播放 | 中文字字幕一区二区三区四区五区 | 在线免费黄色小视频 | 午夜精品久久久久久不卡欧美一级 |