dom4j解析xml问题
Strings="<?xmlversion='1.0'encoding='gb2312'?>"+"<Root><data>"+"<enter>"+"<enterid>11...
String s= "<?xml version='1.0' encoding='gb2312'?>" +
"<Root><data>" +
"<enter>" +
"<enterid>1101080002</enterid>" +
"<entername>沃尔玛超市知春路分店</entername>" +
"<countyid>110108</countyid>" +
"<entertype>01</entertype>" +
"<products>null</products>" +
"<faren>null</faren>" +
"<telephone>010-58733666 </telephone>" +
"<sales>0</sales>" +
"<xinyong>0</xinyong>" +
"</enter>" +
"<enter>" +
"<enterid>1101050001</enterid>" +
"<entername>沃尔玛建国路分店</entername>" +
"<countyid>110105</countyid>" +
"<entertype>01</entertype>" +
"<products>null</products>" +
"<faren>null</faren>" +
"<telephone>010-59603566</telephone>" +
"<sales>0</sales>" +
"<xinyong>0</xinyong>" +
"</enter>" +
"</data></Root>";
SAXReader reader = new SAXReader();
Document xml = reader.read(new ByteArrayInputStream(s
.getBytes("UTF-8")));
List<String> list = new ArrayList<String>();
list = xml.selectNodes("//Root//data//enter");
System.out.println(list);
报错信息
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/JaxenException
at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
at org.dom4j.tree.AbstractNode.selectSingleNode(AbstractNode.java:183)
求解答 展开
"<Root><data>" +
"<enter>" +
"<enterid>1101080002</enterid>" +
"<entername>沃尔玛超市知春路分店</entername>" +
"<countyid>110108</countyid>" +
"<entertype>01</entertype>" +
"<products>null</products>" +
"<faren>null</faren>" +
"<telephone>010-58733666 </telephone>" +
"<sales>0</sales>" +
"<xinyong>0</xinyong>" +
"</enter>" +
"<enter>" +
"<enterid>1101050001</enterid>" +
"<entername>沃尔玛建国路分店</entername>" +
"<countyid>110105</countyid>" +
"<entertype>01</entertype>" +
"<products>null</products>" +
"<faren>null</faren>" +
"<telephone>010-59603566</telephone>" +
"<sales>0</sales>" +
"<xinyong>0</xinyong>" +
"</enter>" +
"</data></Root>";
SAXReader reader = new SAXReader();
Document xml = reader.read(new ByteArrayInputStream(s
.getBytes("UTF-8")));
List<String> list = new ArrayList<String>();
list = xml.selectNodes("//Root//data//enter");
System.out.println(list);
报错信息
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/JaxenException
at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
at org.dom4j.tree.AbstractNode.selectSingleNode(AbstractNode.java:183)
求解答 展开
展开全部
当你想采用dom4j来解析XML文件时你必须得引用jaxen引擎---加载一个包即可。包名叫jaxen-1.1-beta-7.jar
只要你把这个包放到你的lib下(也就是放到Build path下)就OK了。
只要你把这个包放到你的lib下(也就是放到Build path下)就OK了。
参考资料: http://huiqinbo.javaeye.com/blog/617651
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询