Home > Java > javaTutorial > java parsing XML files

java parsing XML files

大家讲道理
Release: 2016-11-10 10:31:07
Original
1523 people have browsed it

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>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template