java 解析XML文件

cnffe 9年前發布 | 979 次閱讀 Java Android Sdutio

       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></pre> 


 本文由用戶 cnffe 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!