【Java】解析xml

xml:

复制代码
  
  
     
  A1234     
  河南省郑州市  
  
     
  B1234     
  河南省郑州市二七区  
  
复制代码

代码:

package parXml;
 
import java.io.File;
import java.util.Iterator;
 
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
 
public class parxml {
    public static void main(String[] argc) {
 
        try {
            File f = new File("data.xml");
            SAXReader reader = new SAXReader();
            Document doc = reader.read(f);
            Element root = doc.getRootElement();
            Element foo;
            for (Iterator i = root.elementIterator("VALUE"); i.hasNext();) {
                foo = (Element) i.next();
                System.out.println(foo.elementText("ADDR"));
                 
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

转载于:https://www.cnblogs.com/tiandsp/p/7467884.html

你可能感兴趣的:(【Java】解析xml)