欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java 解析XML文件,java解析xml, Docum

来源: javaer 分享于  点击 47726 次 点评:213

java 解析XML文件,java解析xml, Docum


       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>
相关栏目:

用户点评