xml在html中格式化输出

    xiaoxiao2021-12-14  19

    属于原创,但是也有其他人的想法

    想在html文件中显示如图所示样式

    1、从后端传到前台是字符串,字符串中是xml文件内容

    2、string类型在传到前台之前需要格式化,才能显示如上图样式

    3、显示到html中必须在<xmp></xmp>标签中

    附上后台格式化xml代码

    java

    private String formatXml(String str) throws Exception { Document document = null; document = DocumentHelper.parseText(str); // 格式化输出格式 OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-8"); StringWriter writer = new StringWriter(); // 格式化输出流 XMLWriter xmlWriter = new XMLWriter(writer, format); // 将document写入到输出流 xmlWriter.write(document); xmlWriter.close(); return writer.toString(); }

    转载请注明原文地址: https://ju.6miu.com/read-964560.html

    最新回复(0)