1

I have problem with by Xinclude or as an entity included files. I need to know, which files have been included by parser. Example:

<?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>
The parser creates DOM successfully, but how to get names of files included? The element xi:include is already replaced with content of file.
Theodor Keinstein
  • 1,653
  • 2
  • 26
  • 47

1 Answers1

1

Extend DefaultHandler and @Overwrite the resolveEntity method. Your implementation will simply print or log the publicId/systemId and return null, so the SAXParser will use the default behaviour to resolve the entities.

Pass your DefaultHandler subclass with the SAXParser constructor.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
  • Thanks a lot. It works. For all included files (either x-included or included as an entity) the method obtains absolute path of a file merged as the `systemId` parameter. – Theodor Keinstein Jul 11 '11 at 11:19