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数据文件结构

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

相关推荐
独断万古他化1 分钟前
Selenium 实战 —— 抽奖系统 UI 自动化测试框架搭建
java·selenium·测试工具·ui·自动化·测试
心勤则明4 分钟前
使用 Spring AI Alibaba MCP 结合 Nacos 实现企业级智能体应用
java·人工智能·spring
ruiang10 分钟前
SQL中字符串截取函数(substring)
java
okiseethenwhat19 分钟前
Java 进程 CPU 飙高排查全流程详解
java·开发语言
2601_9498166820 分钟前
使用rustDesk搭建私有远程桌面
java
看见代码就想敲27 分钟前
java学习之(Maven pom.xml 详细讲解)
java·学习·maven
糖炒栗子032635 分钟前
图片加水印与 EXIF 保留方案
java
tongxh42335 分钟前
Spring Boot问题总结
java·spring boot·后端
Chan1641 分钟前
SpringAI:RAG 最佳实践与调优
java·spring boot·ai·java-ee·intellij-idea·rag·springai
odng42 分钟前
Windsurf / Codex 默认只显示 3 个最近任务,如何改成 100 个
java