public class TestDom4j { public static void main(String[] args) throws Exception{
selectSin(); }
//查询p.xml下的第一个name元素
public static void selectSin() throws Exception {
SAXReader sr=new SAXReader();//创建解析器
Document document=sr.read("src/p.xml");
Element element =document.getRootElement();//得到根元素
List<Element> list=element.elements("p1");
Iterator<Element> i=list.iterator();
while(i.hasNext()) {
Element name=i.next();
String str=name.getText();
System.out.println(str);
}
}
}
异常
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.dom4j.io.SAXContentHandler (file:/D:/eclipse-workspace/day06/lib/dom4j-1.6.1.jar) to method com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser$LocatorProxy.getEncoding()
WARNING: Please consider reporting this to the maintainers of org.dom4j.io.SAXContentHandler
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release