久久久久久久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 示例中缺少)
主站蜘蛛池模板: 成年人黄色一级片 | 久久精品69 | 亚洲一区自拍 | 国产精品美女www爽爽爽视频 | 国产一区二区三区 | 国产精品欧美一区二区 | 成人在线电影网站 | 欧美一区二区三区久久精品 | 91免费入口 | 精品国产一区二区久久 | 国产精品美女久久久久aⅴ国产馆 | 亚洲一本 | 国产一区二区在线免费视频 | 欧美在线一区二区三区四区 | 亚洲精品在线观看视频 | 国产午夜精品一区二区三区嫩草 | 久久精品国产久精国产 | 亚洲精品黑人 | 欧美一区二区在线观看 | 久久www免费人成看片高清 | 欧美日韩黄色一级片 | 这里只有精品99re | 亚洲国产精品人人爽夜夜爽 | 亚洲国产精品激情在线观看 | 久久久成人网 | 国产精品乱码一二三区的特点 | 一级毛片免费看 | 丁香婷婷成人 | 国偷自产av一区二区三区 | 伊人超碰 | 久久亚洲欧美日韩精品专区 | 国产精品久久久久久高潮 | 97超在线视频 | 国产成人精品免费视频大全最热 | 成人影院一区二区三区 | 欧美日韩一区不卡 | 国产乱码久久久 | 日韩在线成人 | 欧美精品久久久 | 国产成人午夜精品影院游乐网 | 最新午夜综合福利视频 |