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

Java:如何防止 EntityResolver#resolveEntity(String publicI

Java: How to prevent #39;systemId#39; in EntityResolver#resolveEntity(String publicId, String systemId) from being absolutized to current working directory(Java:如何防止 EntityResolver#resolveEntity(String publicId, String systemId) 中的
本文介紹了Java:如何防止 EntityResolver#resolveEntity(String publicId, String systemId) 中的“systemId"被絕對化到當前工作目錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想解析以下 XML 文檔以解析其中的所有實體:

 <!DOCTYPE doc SYSTEM 'mydoc.dtd'><doc>&title;</doc>

我的 EntityResolver 應該從數(shù)據(jù)庫中獲取具有給定系統(tǒng) ID 的外部實體,然后進行解析,請參見下圖:

 私有靜態(tài)類 MyEntityResolver{public InputSource resolveEntity(String publicId, String systemId)拋出 SAXException、IOException{//此時systemId總是被絕對化為當前工作目錄,//即使 XML 文檔將其指定為相對的.//例如file:///H:/mydoc.dtd" 而不僅僅是mydoc.dtd"http://為什么???我怎樣才能防止這種情況???SgmlEntity 實體 = findEntityFromDatabase(systemId);InputSource is = new InputSource(new ByteArrayInputStream(entity.getContents()));is.setPublicId(publicId);is.setSystemId(systemId);回報是;}}

我嘗試使用 DOM (DocumentBuilder) 和 SAX (XMLReader),將實體解析器設置為 MyEntityResolver(即 setEntityResolver(new MyEntityResolver())),但 systemIdMyEntityResolver#resolveEntity(String publicId, String systemId) 中總是被絕對化到當前工作目錄.

我也嘗試調(diào)用 setFeature("http://xml.org/sax/features/resolve-dtd-uris", false);,但沒有任何幫助.p>

那么我怎樣才能實現(xiàn)我想要的呢?

謝謝!

解決方案

顯然還有一個接口叫EntityResolver2 是舊 EntityResolver.(談論令人困惑的名字!)

無論如何,我發(fā)現(xiàn) EntityResolver2 實現(xiàn)了我想要的,也就是說,它沒有對 systemId 進行任何更改,所以它始終是指定的在 XML 文檔中.

I want to parse the following XML document to resolve all entities in it:

 <!DOCTYPE doc SYSTEM 'mydoc.dtd'>
 <doc>&title;</doc>

My EntityResolver is supposed to fetch the external entity with the given system ID from the database and then do the resolution, see below for an illustration:

 private static class MyEntityResolver
 {
    public InputSource resolveEntity(String publicId, String systemId)
        throws SAXException, IOException
    {
        // At this point, systemId is always absolutized to the current working directory, 
        // even though the XML document specified it as relative.
        // E.g. "file:///H:/mydoc.dtd" instead of just "mydoc.dtd"
        // Why???  How can I prevent this???

        SgmlEntity entity = findEntityFromDatabase(systemId);
        InputSource is = new InputSource(new ByteArrayInputStream(entity.getContents()));
        is.setPublicId(publicId);
        is.setSystemId(systemId);
        return is;
    }
 }

I tried both using DOM (DocumentBuilder) and SAX (XMLReader), set the entity resolver to MyEntityResolver (i.e. setEntityResolver(new MyEntityResolver())), but systemId in MyEntityResolver#resolveEntity(String publicId, String systemId) is always being absolutized to the current working directory.

I also tried calling setFeature("http://xml.org/sax/features/resolve-dtd-uris", false);, but that didn't help anything.

So how can I achieve what I wanted?

Thanks!

解決方案

Apparently, there is another interface called EntityResolver2 which is the extension of the old EntityResolver. (Talk about confusing names!)

Anyway, I found that EntityResolver2 achieved what I wanted, that is, it does not make any changes to the systemId, so it will always exactly be what was specified in the XML document.

這篇關(guān)于Java:如何防止 EntityResolver#resolveEntity(String publicId, String systemId) 中的“systemId"被絕對化到當前工作目錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(fā)(Google 驅(qū)動器 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(谷歌驅(qū)動api服務賬戶查看上傳文件到谷歌驅(qū)動使用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 示例中缺少)
主站蜘蛛池模板: 日韩免费看视频 | 一区二区三区国产 | 国产欧美精品 | 色接久久| 亚洲在线| 男人的天堂久久 | 日韩色在线 | 久久午夜精品福利一区二区 | 97视频在线观看免费 | 精品1区2区3区 | 日日干日日操 | 狠狠操狠狠搞 | 久久久精品久久久 | 国产三区精品 | 91精品国产一区二区三区 | gav成人免费播放视频 | 国产一区二区久久 | 亚洲欧美中文日韩在线 | 国产精品成人一区二区 | 久久精品一 | 91亚洲精品在线 | 久久爱黑人激情av摘花 | 久久久久久免费观看 | 毛片电影 | 国产精品一区二区久久久久 | 日韩五月天 | 久久国产精品免费一区二区三区 | 久久国内 | 伊人免费在线观看高清 | 一区二区三区高清 | 久久久久久亚洲精品 | 网站黄色在线免费观看 | 亚洲精品国产综合区久久久久久久 | 欧美一级观看 | 日日操夜夜干 | 在线观看第一页 | 污视频免费在线观看 | 国产福利在线视频 | 欧美精品久久久 | 欧美 日韩 中文 | 国产日韩精品视频 |