<?xml version="1.0" encoding="UTF-8"?><bills> <count> <money>987.65</money> <num>18</num> </count> <list> <no>1</no> <outTradeNo>102687459687456</outTradeNo> <userAccount>012563987</userAccount> <rechargeMoney>100.10</rechargeMoney> </list> <list> <no>2</no> <outTradeNo>202687459687456</outTradeNo> <userAccount>012563988</userAccount> <rechargeMoney>110.20</rechargeMoney> </list> <list> <no>3</no> <outTradeNo>302687459687456</outTradeNo> <userAccount>012563989</userAccount> <rechargeMoney>120.03</rechargeMoney> </list>
SAXReader reader = new SAXReader(); Document document = reader.read(multipartFile.getInputStream()); // Search the Signature element // 通过document对象获取根节点bookstore Element root = document.getRootElement(); // 通过element对象的elementIterator方法获取迭代器 Iterator<?> it = root.elementIterator(); // 遍历迭代器,获取根节点中的信息 while (it.hasNext()) { System.out.println("=====开始遍历====="); Element elementFirst = (Element) it.next(); Iterator<?> item = elementFirst.elementIterator(); while (item.hasNext()) { Element elementSecond = (Element) item.next(); System.out.println("节点名:" + elementSecond.getName() + "--节点值:" + elementSecond.getStringValue()); } System.out.println("=====结束遍历======"); }
dom4j解析xml
最新推荐文章于 2024-11-06 19:00:00 发布