我在使用XML解析时遇到问题。
我正在使用dom4J,但是代码似乎从read.read(xml)行跳回了c
public static ConfigFile buildClass(ConfigFile c, String xml) throws ParseException{
try {
SAXReader reader = new SAXReader();
Document doc = reader.read(xml);
Element root = doc.getRootElement();
String version = "";
for ( Iterator i = root.elementIterator( "version" ); i.hasNext(); ) {
Element foo = (Element) i.next();
version = foo.getStringValue();
}
System.err.println(version);
}
catch(Exception ex){
}
return c;
没有控制台错误
最佳答案
您看不到发生了什么,因为您完全忽略了任何错误。至少将catch异常更改为:
catch(Exception ex){
ex.printStackTrace();
}
这样您就可以知道为什么会出现错误。
关于java - 无法使用DOM4J解析XML,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34137557/