通过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;
    }
相关推荐
执明wa3 天前
Android RecyclerView 多类型, 多种 Item
android·xml·开发语言·设计模式·android studio
wl85114 天前
SAP CPI 教程004 如何通过groovy修改XML节点属性值
xml
码匠许师傅5 天前
【C++三方组件】TinyXML2:两个文件的极简 XML 解析器
xml·c++
yuzhiboyouye6 天前
my-batisPlus什么时候用xml什么时候用mapper自带的方法,这两种写法专业一点叫什么,什么场景分别使用
xml
筝筝ba8 天前
如何跳过FFDC
xml·linux·运维·服务器·网络
yuzhiboyouye8 天前
那xml对应的sql语法,列举一下
xml·数据库·sql
筝筝ba13 天前
OpenBMC 自动化测试中的多进程陷阱:从 Execute Process 返回异常到 output.xml 损坏问题分析
xml·linux·运维·服务器·网络
spencer_tseng17 天前
[j2cache ehcache.xml]/tmp/.ehcache-diskstore.lock (Permission denied)
xml·linux·python·ehcache·[j2cache
DevOpenClub18 天前
PDF 多格式解析如何避免混用输出:TEXT、HTML、XML 与 TAG 数据契约
xml·前端·数据库·pdf·html
Java小白笔记19 天前
MyBatis XML Mapper 标签与 CRUD 原理实战
xml·数据库·mybatis