在写毕设的时候在解析XML文件的时候遇到的一个棘手的问题“unknown protocol: c Nested exception: unknown protocol: c”,翻阅了资料说是tomcat的安装路径不能有空格,要么重新安装tomcat,要么以文件的形式进行解析,果断选择第二种,结果如下:
原先的代码:
String path = getServletContext().getRealPath("/cities.xml");
SAXReader reader = new SAXReader();
Document document = reader.read(path);
String xmlText = document.asXML();
修改后的代码如下:
String path = getServletContext().getRealPath("/cities.xml");
SAXReader reader = new SAXReader();
File file = new File(path);
Document document = reader.read(file);
String xmlText = document.asXML();