How to load a relative system DTD into a StAX parser?

salas

New Member
I am using woodstox to implement a StAX parser for XML files. Assume that I have a valid XML file with matching DTD somewhere in a common directory in my filesystem.\[code\]/path/to/test.xml/path/to/test.dtd\[/code\]The XML references to its DTD using a relative system identifier declaration as follows:\[code\]<!DOCTYPE test SYSTEM "test.dtd">\[/code\]From a validation viewpoint, everything seems fine to me. (Is it? xmllint does not complain.) However, when I am trying to parse the file with the code below, woodstox throws a java.io.FileNotFoundException since it cannot find the relative DTD file. It seems to me that the implementation tries to access the DTD file relative to the working directory instead of relative to the XML file object.\[code\]import java.io.FileInputStream;import javax.xml.stream.XMLInputFactory;import javax.xml.stream.XMLStreamConstants;import javax.xml.stream.XMLStreamReader;public class Test { public static void main( String[] args ) throws Exception { FileInputStream fileInputStream = new FileInputStream( args[0] ); XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); XMLStreamReader xsr = xmlInputFactory.createXMLStreamReader(fileInputStream); while( xsr.hasNext() ) { if( xsr.next() == XMLStreamConstants.DTD ) { System.err.println( xsr.getText() ); } } }}\[/code\][*]Is this intentional?[*]Is there a convenient way to convince the StAX parser to load the DTD relative to a given XML file instead of relative to the working directory?
 
Back
Top