hutool解析xml工具类

时间:2025-03-12 08:26:46
//xml字符串转 document对象 Document document = XmlUtil.readXML(xmlData); //根据路径获取Element对象 Element element = XmlUtil.getElementByXPath("//NInstanceData/ScatterData/Component", document); //根据路径获取标签对象,返回的是数组 NodeList sectionList = element.getElementsByTagName("Section"); for (int i = 0; i < sectionList.getLength(); i++) { Node section = sectionList.item(i); //根据路径获取标签后获取标签的DisplayName属性 String title = XmlUtil.getElementByXPath("Code", section).getAttribute("DisplayName"); //根据路径获取标签后获取标签的内容 String value = XmlUtil.getByXPath("Text", section, XPathConstants.STRING); }