java解析xml文件
package com.framework.common.util;
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.Namespace;
import org.jdom.input.SAXBuilder;
public class XMLUtil {
public String getXmlUrl(String path) throws JDOMException, IOException{
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File(path));
Element root = doc.getRootElement();
List jiedian = root.getChildren();
//获得XML中的命名空间(XML中未定义可不写)
Namespace ns = root.getNamespace();
Element et = null;
String str = "";
for(int i=0;i<jiedian.size();i++){
et = (Element) jiedian.get(i);//循环依次得到子元素
str = et.getChild("url",ns).getText();
}
return str;
}
}