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

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

相关推荐
mzhan0179 分钟前
Linux: compare的直观性
java·linux·服务器
mask哥14 分钟前
力扣算法java实现汇总整理(下)
java·算法·leetcode
代码中介商15 分钟前
栈结构完全指南:顺序栈实现精讲
c语言·开发语言·数据结构
小陈的进阶之路20 分钟前
Python系列课(2)——判断
java·前端·python
刚子编程23 分钟前
C# Join 进阶:GroupJoin、性能对决与自定义比较器
java·servlet·c#·join
漫随流水29 分钟前
IDEA快速生成构造方法(空参、带参)
java·intellij-idea
spencer_tseng44 分钟前
Spring Boot 3.0+ jakarta.*
java·spring boot
Bat U1 小时前
JavaEE|文件操作和IO
java·开发语言
DavidSoCool1 小时前
Spring AI Alibaba ReactAgent 调用Tool 实现多轮对话
java·人工智能·spring·多轮对话·reactagent
神所夸赞的夏天2 小时前
如何获取多层json数据,存成dictionary,并取最大最小值
java·前端·json