JAVA解析XML字符串(转化成Map类型)

public static Map readStringXml(String xml) throws DocumentException {
        Document doc = DocumentHelper.parseText(xml);
        Element books = doc.getRootElement();
        System.out.println("rootNode:" + books.getName());
        Iterator Elements = books.elementIterator();
        Map map = new HashMap<>();
        while (Elements.hasNext()) {
            Element user = (Element) Elements.next();
            System.out.println("node=" + user.getName() + "\ttext=" + user.getText());
            map.put(user.getName(), user.getText());
        }
        return map;
    }

你可能感兴趣的:(JAVA解析XML字符串(转化成Map类型))