黑马程序员技术交流社区

标题: 07 [打印本页]

作者: emmm...    时间: 2018-1-18 22:51
标题: 07
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;
        
    }
}



作者: 1414225997    时间: 2018-1-19 11:41
嘿嘿,看不懂
作者: emmm...    时间: 2018-1-20 21:36
1414225997 发表于 2018-1-19 11:41
嘿嘿,看不懂

多敲几遍就会了
作者: xiongliu    时间: 2018-1-21 13:49
这怎么跟后面那篇一样的呀,感觉
作者: 渝小妹    时间: 2018-1-21 16:54
期待你每天的进步   温故而知新
作者: 陈文老师    时间: 2018-1-23 09:21
继续加油!每天总结,每天成长!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2