Loading...
 Rouse LifeJavaDocument parse xml
rouse life
Document parse xml
author / meteor   comefrom:Rouse Life

document parse xml demo:

----------------------------------------------------------

config.xml file

<?xml version="1.0" encoding="UTF-8"?>
<param>
 <add name="pageSize" value="15">page</add>
 <add name="webSite" value="Rouselife">Test</add>
</param>

----------------------------------------------------------

Class file:

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

 

public class Util {

    public static String getXmlValue(String path, String param){
       SAXReader saxReader = null;
       Document doc = null;
       try {
           File f = new File(path);
           saxReader = new SAXReader();
           doc = saxReader.read(f);
           List<Element> list = doc.selectNodes("//param//add");

           for (Element add: list) {
               System.out.println(add.attribute("name").getStringValue());

               System.out.println(add.attribute("value").getStringValue());

               System.out.println(add.getText());
           }

       } catch (Exception e) {
       }
       return null;
   }

}


Last updated at [2010-4-22 16:14:16]

zhqhao  [2010-4-9 13:13:26] create | Loading... | [ return top ]  
head icon
other article
Loading...
rouse studio
Contribute | Audit Rule | Copyright | Privacy | SiteMap
Copyright © 2004-2010 rouse studio All Rights Reserved.
Powered by rouse cms 2.3 © 2009-2010 rouse studio.