测试代码:
public static void main(String args[]){ try{
String sourceFile="E:\\4-2.xml";
SAXBuilder builder = new SAXBuilder();
Format format=Format.getPrettyFormat() ;
XMLOutputter outp=new XMLOutputter(format); Document xmlDoc=builder.build(sourceFile);
// Class.forName("XPath");
XPath path=XPath.newInstance("*");
// do system output
outp.output(xmlDoc , System.out ); // Element ele0=(Element) path.selectSingleNode(xmlDoc.getRootElement() );
Element ele0=(Element) xmlDoc.getRootElement() ;
outp.output(ele0 , System.out); }catch(Exception e){
e.printStackTrace() ;
} }
public static void main(String args[]){ try{
String sourceFile="E:\\4-2.xml";
SAXBuilder builder = new SAXBuilder();
Format format=Format.getPrettyFormat() ;
XMLOutputter outp=new XMLOutputter(format); Document xmlDoc=builder.build(sourceFile);
// Class.forName("XPath");
XPath path=XPath.newInstance("*");
// do system output
outp.output(xmlDoc , System.out ); // Element ele0=(Element) path.selectSingleNode(xmlDoc.getRootElement() );
Element ele0=(Element) xmlDoc.getRootElement() ;
outp.output(ele0 , System.out); }catch(Exception e){
e.printStackTrace() ;
} }
下班时候,拉一个也是做java的同事帮忙看了,仓促下没有找到,他对这个工具不是很熟悉。
有哪位idea用的比较多的,也来试验一下。帮忙啊!!!!!!
万谢!!!!!!!!!!!!!
今天用了Eclipse工具,还是一样的结果。
编译都通过了,就是在运行的时候出错,实在是奇怪了。
用普通方式解析时,没有任何问题,但用xpath时就报这个错,请哪位高手快快现身!!
别说什么classpath的问题,太小儿科了,根本不是