日期:2014-05-20 浏览次数:20778 次
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
public class ReadXML {
public List GetCompanyList(String XML_url){
try {
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(XML_url);
Element root = doc.getRootElement();
List list = root.getChildren();
ArrayList<CompanyListForm> formList = new ArrayList<CompanyListForm>();
Iterator iter = list.iterator();
while (iter.hasNext()) {
Element e = (Element) iter.next();
CompanyListForm companyListForm = new CompanyListForm();
companyListForm.setCompany_name(e.getChildText("company_name"));
companyListForm.setCompany_email(e.getChildText("company_email"));
formList.add(companyListForm);
}
Iterator iterator = moList.iterator();
while (iterator.hasNext()) {
CompanyListForm companyListForm = (CompanyListForm) iterator.next();
System.out.println("company_name:" + companyListForm.getCompany_name());
System.out.println("company_email:" + companyListForm.getCompany_email());
}
return formList;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
ReadXML readXml = new ReadXML();
readXml.GetCompanyList("e:\\company_list.xml");
}
}