2读XML
class Test2{
SAXReader read=new SAXReader();
Document doc=read.read(new FileInputStream(“”));
Element root=doc.getRootElement();
root.getName();
//获得子元素节点
List list=root.elements();
//获得指定名字的所有子元素节点
List list=root.elements(“hello”);
//获取第三个hello element
Element e=(Element)list.get(2);
//获得元素文本
e.getText();
//返回第一个子元素节点
Element e=root.element(“hello”);
//返回属性,也是Attribute类型
Attribute attr1=e.attribute(“name”);
String s=attr1.getValue();
或者合并为一步:
String s= e.attributeValue(“name”);
//返回元素所有属性集合
List list=e.attributes();
}