java 解析c语言程序xml数据文件

css 复制代码
@GetMapping("/getHostMenuButtons")
    @Operation(summary = "创建试卷分类")
    @PermitAll
//    @PreAuthorize("@ss.hasPermission('jd:index:query')")
    public JSONObject getJd() {
        //1、读取文件并转换为Document文档对象
        Document doc = null;
        try {
            doc = new SAXReader().read(new File("F:\\zty\\test1\\ruoyi-vue-pro-master\\yudao-ui-admin-vue2\\src\\views\\jd\\w2101.xml"));
        } catch (DocumentException e) {
            throw new RuntimeException(e);
        }

        //2、使用asXML()方法将DOM文档对象转换为字符串
        String s = doc.asXML();

        //3、调用自定义的方法转换为JSON数据格式
        JSONObject jsonObject = startXMLToJSON(s);
//        jsonObject.toJSONArray(Collections.singleton("shape"));

        //4、输出结果
//        System.out.println(jsonObject.size());
        return jsonObject;
    }
css 复制代码
/**
     * 自定义
     */
    public static JSONObject startXMLToJSON(String xml) {
        //1、定义JSON对象保存结果
        JSONObject result = new JSONObject();
        try {
            //2、使用DocumentHelper.parseText()转换为DOM文档对象
            Document document = DocumentHelper.parseText(xml);
            //3、获取DOM文档根节点
            List<Node> elementList = document.getRootElement().content();
            //4、调用自定义的方法转换为JSON数据格式
            String shape = elementList.get(0).getDocument().asXML().replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "")
                    .replace("<JDOPC>", "")
                    .replace("</JDOPC>", "");
            result = new JSONObject(shape);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return result;
    }

c语言xml数据文件结构

请求接口响应前端对象集合

相关推荐
小蒜学长35 分钟前
编程语言在线学习平台的设计与实现(代码+数据库+LW)
java·spring boot·后端·编程语言在线学习平台·在线编码
步行cgn1 小时前
Spring MVC 执行流程详解:一次请求的完整旅程
java·spring·mvc
增量星球1 小时前
Spring AI 2.0 Tool Calling 到底怎么跑起来的:从 @Tool 到两次模型调用
java·agent·springai·ai coding
步行cgn1 小时前
Spring MVC 九大核心角色详解:请求处理链路中的每一个关键组件
java·spring·mvc
智恒百亿1 小时前
一台 5090 八卡服务器怎么分给一个团队用?多模型多任务的显存分配实战
java·大数据·人工智能
瑞码空间2 小时前
面向接口编程与开闭原则在模拟 JDBC 驱动中的应用
java·jdbc
Félix2512 小时前
Nacos学习笔记(SpringBoot/SpringCloud)
java·spring boot·spring
文丑颜不良啊2 小时前
LeetCode1581~1600题目解析
java·leetcode
香蕉大香蕉(06敬畏市场)2 小时前
MySQL 单点详解(06)
java·数据库·mysql·博客·实习
lqbzlll2 小时前
Spring Boot 开启虚拟线程后接口反而变慢了?4 个排查方向和对应修法
java·spring boot·后端