public static void main(String[] args) {
try {
String c=getBean("userService");
System.out.println(c);
} catch (Exception e) {
TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test
public void a() throws Exception {
SAXReader reader =new SAXReader();
Document document= reader.read("NewFile.xml");
Element root=document.getRootElement();
Element pElement=root.element("person");
Element n=pElement.element("name");
System.out.println(n.getText());
}
@Test
public void a1() throws Exception{
SAXReader reader =new SAXReader();
Document document= reader.read("NewFile.xml");
List<Node> nodes=document.selectNodes("//name");
for (Node node : nodes) {
Element element=(Element) node;
String name =element.getStringValue();
System.out.println(name);
}
}
public static String getBean(String id) throws Exception{
SAXReader reader =new SAXReader();
Document document= reader.read("xml2.xml");
Node node=document.selectSingleNode("//bean[@id='"+id+"']");
Element element=(Element) node;
String clazz=element.attributeValue("class");
return clazz;
}
}
|
|