zoukankan      html  css  js  c++  java
  • xml格式内容转换成字符串

    将xml格式的内容,压缩成一行字符串

    public void fun1() throws JDOMException, IOException {
            SAXBuilder oBuilder = new SAXBuilder();
            File oFile = new File(path);
            Document oXmlDoc = oBuilder.build(oFile);
            String xmlString="";
            Format format = Format.getPrettyFormat();
            format.setEncoding("UTF-8");
            XMLOutputter xmlout = new XMLOutputter(format);
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            xmlout.output(oXmlDoc, bo);
            xmlString = bo.toString();
            BufferedReader reader = new BufferedReader(new StringReader(xmlString));
            StringBuffer result = new StringBuffer();
            try {
                String line;
                while ((line = reader.readLine()) != null)
                    result.append(line.trim());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            xmlString = result.toString();
            boolean xmlHeader = false;
            if (!xmlHeader) {
                xmlString = xmlString.replace("<?xml version="1.0" encoding="UTF-8"?>", "");
            }
            System.out.println("jdom解析xml文件转换字符串:");
            System.out.println(xmlString);
        }
  • 相关阅读:
    2019.9.5 Balanced Lineup
    0060-最小的四位数
    0059-乘积问题
    0058-简单的阶乘
    0057-简单的累加
    0056-简单的博弈
    神奇代码
    测评结果大百科
    0055-空气质量检测
    0054-软件版本号问题
  • 原文地址:https://www.cnblogs.com/KevinFeng/p/15194111.html
Copyright © 2011-2022 走看看