我正在使用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。我遗失的任何签名/协议?
谢谢, 巴斯卡尔
答案 0 :(得分:4)
试试这个:
XMLStreamReader streamReader = factory.createXMLStreamReader(
new FileReader("data\\test.xml"));