XML之JDOM解析

前端之家收集整理的这篇文章主要介绍了XML之JDOM解析前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<?xml version="1.0" encoding="GB2312"?> <RESULT> <VALUE>    <NO>A1234</NO>    <ADDR>四川省XX县XX镇XX路X段XX号</ADDR> </VALUE> <VALUE>   <NO>B1234</NO>    <ADDR>四川省XX市XX乡XX村XX组</ADDR> </VALUE> </RESULT> java: package www.yq.com.src; import java.io.File; import java.io.IOException; import java.util.List; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; /** * @Project XMLSimpleTest * @File MyJdomXmlReader.java * @Package www.yq.com.src * @Date 2016年1月26日 上午11:26:01 * @Author * @email */ public class MyJdomXmlReader { public static void main(String[] args) throws JDOMException,IOException { File f = new File("E:\\qi.xml"); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element rootElement = doc.getRootElement(); List children = rootElement.getChildren(); for (int i = 0; i < children.size(); i++) { System.out.println("车牌号:"+((Element)children.get(i)).getChild("NO").getText()); System.out.println("车牌地址:"+((Element)children.get(i)).getChild("ADDR").getText()); } } }

猜你在找的XML相关文章