如何在不知道xml结构时用jdom解析

前端之家收集整理的这篇文章主要介绍了如何在不知道xml结构时用jdom解析前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码如下:

SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(new File("C:\\a.xml"));

        Element root = doc.getRootElement();
        String rootName = root.getName(); //"person"
        List dataList = root.getChildren();

        Iterator i = dataList.iterator();
        while (i.hasNext()) {
         Element e = (Element) i.next();
         String eKey = e.getName(); //"name","age","address"
         String eValue = e.getText(); //"wang","22","beijin"
         System.out.println("eKey==="+eKey+"  ;eValue==="+eValue);
        }

参考地址:来自https://zhidao.baidu.com/question/49517776.html

原文链接:https://www.f2er.com/xml/294304.html

猜你在找的XML相关文章