I am using woodstox to implement a StAX parser for XML files. Suppose I have a valid XML file with the corresponding DTD somewhere in a shared directory on my file system.
/path/to/test.xml
/path/to/test.dtd
XML references the DTD using the relative system identifier declaration as follows:
<!DOCTYPE test SYSTEM "test.dtd">
From the point of view of verification, everything seems fine to me. (Is this? Xmllint does not complain.) However, when I try to parse the file using the code below, woodstox throws a java.io.FileNotFoundException because it cannot find the relative DTD file. It seems to me that the implementation is trying to access the DTD file relative to the working directory, and not the XML file object.
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() );
}
}
}
}
- Is it intentional?
- StAX DTD XML , ?