好了,下面看一下xml解析中的JDOM解析java
直接上代碼XML:dom
<?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:ui
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()); } } }1
運行結果:code
JDOM解析是需jar包的,而後想操做的小夥伴本身下載一下jar包吧!xml