xml字符串转换为实体类对象(⼦节点中重复参数(情况
⼀))
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
String xml = "<itemInfoQueryRequestDown>"
+ "<checkword>校验字段</checkword>"
+ "<serialNumber>流⽔号</serialNumber>"
+ "<warehouseCompanyCode>第三⽅仓储公司代码</warehouseCompanyCode>"
+ "<companyCode>公司代码</companyCode>"
+ "<pageIndex>指定页</pageIndex>"
+ "<itemCodeList>"
+ "<itemCode>商品编号</itemCode>"
+ "</itemCodeList>"
+ "<itemCodeList>"
+ "<itemCode>商品编号</itemCode>"
+ "</itemCodeList>"
+ "</itemInfoQueryRequestDown>";
Document doc = null;
List list = new ArrayList<String>();
try {
doc = DocumentHelper.parseText(xml);
Element rootElt = RootElement(); // 获取根节点
String checkword = rootElt.elementTextTrim("checkword");
String serialNumber = rootElt.elementTextTrim("serialNumber");
String warehouseCompanyCode = rootElt.elementTextTrim("warehouseCompanyCode");
String companyCode = rootElt.elementTextTrim("companyCode");
String pageIndex = rootElt.elementTextTrim("pageIndex");
Iterator iters = rootElt.elementIterator("itemCodeList");
while (iters.hasNext()) {
Element itemEle = (Element) ();
String itemCode = itemEle.elementTextTrim("itemCode");
dom4j读取xmllist.add(itemCode);
}
System.out.println(list);
} catch (Exception e) {
e.printStackTrace();
}
转载于:my.oschina/u/4048873/blog/2989330

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。