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

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

相关推荐
bing_158几秒前
Spring Boot 项目中什么时候会抛出 FeignException?
java·spring boot·后端
Java&Develop31 分钟前
springboot + mysql8降低版本到 mysql5.7
java·spring boot·后端
sg_knight34 分钟前
从单体架构到微服务:架构演进之路
java·spring boot·spring·spring cloud·微服务·云原生·架构
夜晚中的人海35 分钟前
【C语言】初阶数据结构相关习题(二)
c语言·开发语言·数据结构
武昌库里写JAVA1 小时前
MacOS Python3安装
java·开发语言·spring boot·学习·课程设计
eternal__day1 小时前
Spring Cloud:构建云原生微服务架构的最佳工具和实践
java·spring cloud·微服务·云原生·架构
cdut_suye1 小时前
【Linux系统】从 C 语言文件操作到系统调用的核心原理
java·linux·数据结构·c++·人工智能·机器学习·云计算
forestsea1 小时前
Maven 插件参数注入与Mojo开发详解
java·maven·mojo
荔枝吻1 小时前
【抽丝剥茧知识讲解】引入mybtis-plus后,mapper实现方式
java·sql·mybatis
在未来等你2 小时前
互联网大厂Java求职面试:构建高并发直播平台的架构设计与优化
java·spring boot·微服务·kubernetes·高并发·分布式系统·直播平台