首页 > 编程语言 > 详细

java 解析XML文件

时间:2015-11-05 10:49:58      阅读:338      评论:0      收藏:0      [点我收藏+]
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();                
        DocumentBuilder builder = factory.newDocumentBuilder();      
        Document document = builder.parse(inputStream);      
        Element element = document.getDocumentElement();     

        NodeList dataNodes = ((Element)element.getElementsByTagName("Application").item(0)).getChildNodes();
        for(int i = 0; i < dataNodes.getLength(); i++){
            if("Version".equals(dataNodes.item(i).getNodeName())){
                System.err.println("版本信息 : " + dataNodes.item(i).getFirstChild().getNodeValue());
            }else if("ChkUpdate".equals(dataNodes.item(i).getNodeName())){
                System.err.println("版本信息 : " + dataNodes.item(i).getFirstChild().getNodeValue());
            }else if("DownLoad".equals(dataNodes.item(i).getNodeName())){
                System.err.println("版本信息 : " + dataNodes.item(i).getFirstChild().getNodeValue());
            }

        }


        <?xml version="1.0" encoding="UTF-8"?>
        <Applications>
            <Application>
                <Version>1.7</Version>
                <ChkUpdate>baidu.com</ChkUpdate>
                <DownLoad>sohu.com</DownLoad>
            </Application>
        </Applications>

java 解析XML文件

原文:http://my.oschina.net/u/1468096/blog/526101

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!