<accountCheckResult>//根元素<payOrder><payOrderId>20091209214739</payOrderId><merOrderId>111123456</merOrderId><merSendTime>2008-07-01</merSendTime><amountSum>500.00</amountSum><payBank>abc</payBank><state>1</state></payOrder><payOrder>...</payOrder><payOrder>...</payOrder></accountCheckResult>这是xml中的内容,怎么从这个xml中取出所有的payOrder放入list呢(已经有payorder这个bean)请帮我写几句代码
2 回答
蛊毒传说
TA贡献1895条经验 获得超3个赞
dom4j中,使用Element.attributes方法可以获取到节点的属性,而使用elements则可以获取相应的子节点
比如:
Element root = doc.getRootElement();
List attrList = root.attributes();
for (int i = 0; i < attrList.size(); i++) {
//属性的取得
Attribute item = (Attribute)attrList.get(i);
System.out.println(item.getName() + "=" + item.getValue());
}
List childList = root.elements();
for (int i = 0; i < childList.size(); i++) {
//子节点的操作
Element it = (Element) childList.get(i);
//对子节点进行其它操作...
}
添加回答
举报
0/150
提交
取消