I try to unmarhshal a file XML file (test.xml
) with JAXB (javax.xml.bind.JAXB
) but it gives me this error:
[org.xml.sax.SAXParseException; systemId: file:/C:/Users/EXAMPLE/AppData/Local/Eclipse/workspace_4.4.0/EXAMPLE/test.xml; lineNumber: 2; columnNumber: 42; Externe DTD: Lesen von externer DTD "example.dtd" nicht erfolgreich, da "file"-Zugriff wegen der von der Eigenschaft "accessExternalDTD" festgelegten Einschränkung nicht zulässig ist.]
English Translation:
Reading from external DTD "example.dtd" not succesful , cause "File"-Access is not allowed by the Restriction set by the Properties "accessExternalDTD"
Solutions already tried:
accessExternalDTD
properties.Stuff to notice:
.dtd
and .xml
file and it worked well<!DOCTYPE EXAMPLE SYSTEM "example.dtd">
import javax.xml.bind.*;
import javax.xml.stream.*;
import javax.xml.transform.stream.StreamSource;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Customer.class);
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource("input.xml"));
Unmarshaller unmarshaller = jc.createUnmarshaller();
Customer customer = (Customer) unmarshaller.unmarshal(xsr);
}
}
The accessExternalDTD
property can be controlled with the system property javax.xml.accessExternalDTD
, so start your program with -Djavax.xml.accessExternalDTD=true
and it should work. It should also be possible to set the property on the unmarshaller, try this:
unmarshaller.setProperty(javax.xml.XMLConstants.ACCESS_EXTERNAL_DTD, Boolean.TRUE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With