今天的课程比较轻松,因为只做了解,连学习反馈都免了
不过还是要汇报一下今天学习内容
public static void main(String[] args) throws Exception {
Document document = gongju.get();
//System.out.println(document);
Element rootElement = document.getRootElement();
System.out.println("-----------查看真州-----------------");
List elements = rootElement.elements();
Element el = (Element) elements.get(0);
String elementText = el.elementText("Name");
System.out.println(elementText);
System.out.println("--------------查看所有----------------");
hehe(rootElement);
System.out.println("-------------更改-----------------");
/*List <Element>elements2 = rootElement.elements();
Element element = elements2.get(3);
element.setText("安顺");
gongju.xiehui(document);*/
System.out.println("--------------删除-----------------");
/*List<Element> elements2 = rootElement.elements();
Element element = elements2.get(1);
Element parent = element.getParent();
parent.remove(element);
gongju.xiehui(document);*/
System.out.println("---------------添加-------------------");
/*Element addElement = rootElement.addElement("City");
addElement.setText("贵阳");
gongju.xiehui(document);*/
System.out.println("-------------指定添加-------------------------");
/*Element createElement = DocumentHelper.createElement("City");
createElement.setText("六盘水");
List elements2 = rootElement.elements();
elements2.add(1, createElement);
gongju.xiehui(document);*/
}
public static void hehe(Element rootElement){
System.out.println(rootElement.getName());
List<Element> elements = rootElement.elements();
for (Element object : elements) {
hehe(object);
}
}
}
|
|