public List getDto(String xmlStr){
List list = new ArrayList();
StringReader read = new StringReader(xmlStr);
//创建新的输入源SAX 解析器将使用 InputSource 对象来确定如何读取 XML 输入
InputSource source = new InputSource(read);
//创建一个新的SAXBuilder
SAXBuilder sb = new SAXBuilder();
try {
//通过输入源构造一个Document
Document doc = sb.build(source);
//取的根元素
Element root = doc.getRootElement();
List child = root.getChildren();
Element e = null;
InquiryGGCostClassInfoDto dto;
for (int i = 0; i < child.size(); i++){
dto = new InquiryGGCostClassInfoDto();
e = (Element)child.get(i);
dto.setId(e.getChildText("ID"));
dto.setOperationType(e.getChildText("OPERATION_TYPE"));
dto.setBillClass(e.getChildText("BILL_CLASS"));
dto.setFirstCategoryCode(e.getChildText("FIRST_CATEGORY_CODE"));
dto.setFirstCategoryName(e.getChildText("FIRST_CATEGORY_NAME"));
dto.setSecondCategoryCode(e.getChildText("SECOND_CATEGORY_CODE"));
dto.setSecondCategoryName(e.getChildText("SECOND_CATEGORY_NAME"));
list.add(dto);
}
}catch(JDOMException e){
e.printStackTrace();
}catch(IOException ioe){
ioe.printStackTrace();
}
return list;
}
XML解析
最新推荐文章于 2024-07-22 23:00:53 发布