Project

Profile

Help

Support #5473

open

Error on XSLT transform because DTD not found,

Added by Pankaj Gupta 11 days ago. Updated 11 days ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2022-05-05
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

I am using saxon9ee.jar. I need to apply an XSLT within an existing java program. I am getting the XML file as an input stream. The problem is that the XML contains a DTD. I have the DTD file but don’t know where to place it and tell the java runtime where to find it.

This is being done programmatically, not by the command line.

The xml contains:

Error reported on transform is: I/O error reported by XML parser processing null: /ST26SequenceListing_V1_3.dtd (No such file or directory)

code has Xslt30Transformer.transform(source, destination) where it fails

Any help would be appreciated.

I am new to this. From what I have read t seems the xml parser is failing, but I don't know how to get it to work. Thanks.

Actions #1

Updated by Pankaj Gupta 11 days ago

xml (it isn't a file) contains

Actions #2

Updated by Pankaj Gupta 11 days ago

xml has in it reference to: ST26SequenceListing_V1_3.dtd

Actions #3

Updated by Michael Kay 11 days ago

There are two ways to get the relative URI ST26SequenceListing_V1_3.dtd to resolve.

The first is to make sure that the parser is given a correct base URI, that is a file in the directory containing ST26SequenceListing_V1_3.dtd. You can supply the base URI in the "systemId" property of the Source object passed as input to the transformation. If you supply a StreamSource based on a File or URI this will be set up automatically, but if you supply for example a Stream or a Reader then it needs to be done manually.

The second way is to set up a resolver as a callback which the XML parser calls when it needs to resolve the URI. You can do this at the XML parser level (supply a SAXSource containing an XMLReader whose EntityResolver property has been set to a suitable callback), or you can do it at the Saxon Configuration level - in the latest 11.x release, use Processor.getUnderlyingConfiguration().setResourceResolver().

Actions #4

Updated by Pankaj Gupta 11 days ago

Thank you. The first option looks easier, but the code is deployed on an application server so I don't know what base URI I should be providing.

I googled for the dtd file and downloaded it. I can probably put it under the resources folder of the app server. Are there any code examples of similar things?

Actions #6

Updated by Pankaj Gupta 11 days ago

The above worked.

Thank you so much for your help. Greatly appreciate it.

Please register to edit this issue

Also available in: Atom PDF