通过hutool生成xml

通过hutool生成如下xml文件

生成代码:

java 复制代码
/**
	param list :数据库查询到的数据
*/
private static String createXml(List<Map<String, Object>> list) {
        Document doc = XmlUtil.createXml(); // 5.8+ 方法
        // ① 根元素(标准 SOAP 命名空间,URI 不能有空格)
        Element envelope = doc.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "soapenv:Envelope");
        envelope.setAttribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
        envelope.setAttribute("xmlns:impl", "http://mes.baicmotor.com");
        doc.appendChild(envelope);

        // ② Header
        envelope.appendChild(doc.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "soapenv:Header"));

        // ③ Body
        Element body = doc.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "soapenv:Body");
        envelope.appendChild(body);

        // ④ XGB01LIST(放在 impl 命名空间)
        Element xgbListRoot = doc.createElementNS("http://mes.baicmotor.com", "impl:XGB01LIST");
        body.appendChild(xgbListRoot);

        // ⑤ 循环放 <xgbList>(无命名空间,仅属性)
        for (Map<String, Object> map : list) {
            Element item = doc.createElementNS(null, "xgbList");
            item.setAttribute("vihcleType", map.get("vihcleType").toString());
            item.setAttribute("isGb", map.get("isGb").toString());
            xgbListRoot.appendChild(item);
        }

        String xml = XmlUtil.toStr(doc, false);
        return xml;
    }
相关推荐
IT_Octopus21 小时前
一次由 RestTemplate 引发的 Connection reset:被 XML 截胡的请求体
xml·java·spring boot
Dontla21 小时前
网站爬虫控制策略介绍(robots.txt、sitemap.xml、x-robots-tag、noindex、nofollow)网站索引
xml·爬虫·dubbo
风起洛阳@不良使2 天前
spring中xml和注解开发的对比
xml·java·spring
Mikowoo0073 天前
批量汇总XML格式的发票信息
xml·python
逃逸线LOF3 天前
xml文件如何加载properties文件(spring容器加载properties文件)
xml
前网易架构师-高司机6 天前
带标注的山体滑坡塌方数据集数据集,识别率78.1%,974张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·自然灾害·山体滑坡
程序媛kelly6 天前
.xml / .jrxml 文件怎么打开?OpenFiles 实测预览、编辑、搜索与 AI 摘要排查流程
xml·人工智能·jrxml
潘潘的嵌入式日记6 天前
改完Keil工程文件被缓存覆盖?——uvprojx编辑的进阶四坑
xml·嵌入式·keil·调试·mdk·工程文件
Full Stack Developme7 天前
Flowable XML标签大全
xml
C137的本贾尼7 天前
第九篇:微服务与分布式——把一个大系统拆成多个小服务
xml·spring boot·后端