簡體   English   中英

Java 和 XML:如何獲取包含文件的列表

[英]Java and XML: How to get list of included files

我對 Xinclude 或作為實體包含文件有疑問。 我需要知道,解析器包含了哪些文件。 例子:

<?xml version="1.0" ?>
<!DOCTYPE docBookChapter [
    <!ENTITY externalFile SYSTEM "entityIncluded.xml">
]>
<chapter xmlns="http://www.w3.org/1999/xhtml"
xmlns:xi="http://www.w3.org/2001/XInclude">
    <title>Third chapter</title>
    <xi:include href="xIncluded.xml"/>
    <chapter>
        &externalFile;</chapter>
</chapter>
解析器成功創建 DOM,但如何獲取包含的文件名? 元素xi:include已經替換為文件的內容。

擴展DefaultHandler@Overwrite resolveEntity方法。 您的實現將簡單地打印或記錄 publicId/systemId 並返回null ,因此SAXParser將使用默認行為來解析實體。

使用SAXParser構造函數傳遞DefaultHandler子類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM