A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© emmm... 中级黑马   /  2018-1-18 22:51  /  1611 人查看  /  5 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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;
        
    }
}


5 个回复

倒序浏览
嘿嘿,看不懂
回复 使用道具 举报

多敲几遍就会了
回复 使用道具 举报
这怎么跟后面那篇一样的呀,感觉
回复 使用道具 举报
期待你每天的进步   温故而知新
回复 使用道具 举报
继续加油!每天总结,每天成长!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马