我正在使用 JAXB 来解组 XML 文档。在解析 XML 时,它会抛出一个用 XMLStreamException 包装的 MalformedURLException。我的理解是,在创建 XMLStreamReader 对象本身时,它会引发异常。请问有什么建议吗?
我正在使用的代码片段:
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLResolver resolver = new XMLResolver(); //to capture systemID, base URI etc.
xif.setXMLResolver(resolver);
//Throws MalformedURLException while processing the below line
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(fileToProcess));
JAXBContext jaxbContext = JAXBContext.newInstance(MyPackage.MyClassName.class);
这是异常跟踪:
class javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException: java.net.MalformedURLException: no protocol: [XML_FILEPATH/XML_FILE_NAME]
fileToProcess是一个包含绝对路径的字符串,例如 /home/project/input/myproject.xml
运行时 JDK 为 1.7。我缺少任何签名/协议吗?
谢谢,巴斯卡