hutool处理xml的方法

  • Post author:
  • Post category:其他


一,官网方法

Document docResult=XmlUtil.readXML(xmlFile);
//结果为“ok”
Object value = XmlUtil.getByXPath("//returnsms/message", docResult, XPathConstants.STRING);


Hutool参考文档

二,其他方法

String xml="<?xml version="1.0" encoding="UTF-8" ?><root><content><data>1111</data></content></root>"

Map<string, Object> result1 = new HashMap<>(50);

Map<string, Object> stringObjectMap =XmlUtil.xmlToMap(xml, result1);

Map<string, Object> root = BeanUtil.beanToMap(stringObjectMap.get("root"));
Map<string, Object> contents =BeanUtil.beanToMap(root.get("contents"));
List<Map<string, Object>> detailList = new ArrayList<>();
if (!(contents.get("data") instanceof List)) {
detailList.add(BeanUtil.beanToMap(contents.get("data")));
} else {
detaillist =ListUtil.toList(contents.get("data")).stream().map(BeanUtil::beanToMap).collect(Collectors.toList());
}



版权声明:本文为weixin_41427294原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。