html+注释格式化,使用xml注释来生成格式化的html输出

我试图从我在xml文件中的注释中生成一个格式良好的html文档。目前我有一个xml文件,用于生成xml表格的html列表。为了让我添加有关表格的评论,我手动将注释添加到输出html文件中。使用xml注释来生成格式化的html输出

我想如果可能将html代码放在xml文件中作为注释并让xslt使用注释来创建格式正确的文档。

这是注释的xml文件的一部分。这里有html新行语法,我希望xslt读取为html。我在想,必须有更好的方法来使用raw xml来创建它,但是,我不希望在xml文件中读取注释,因此不希望它作为表项。

这是我使用注释的xsl文件的一部分,但它不解释html。

所需的输出看起来是这样的手动格式化时:

ers_benchmark_defn
This table contains mapping between hierarchy nodes and their respective benchmarks. The columns should be populated as follows:
  • HIERARCHY_NODE

    This column contains the name of the hierarchy node in the ERS Risk Hierarchy.

  • BENCHMARK

    The column can be populated with either;

    a Calypso portfolio name,

    an ERS Risk Hierarchy name, or

    an ERS Risk Hierarchy node name.

    In the latter case, the column should be populated with the hierarchy node name and the hierarchy to which it belongs, separated by a percentage symbol, %.

  • BENCHMARK_TYPE

    If the value in the benchmark column is an ERS hierarchy or hierarchy node name, this column should be populated with the value HIERARCHY. Otherwise, when using a Calypso portfolio name, it should not be populated.

  • SCALING_FACTOR

    This column should be populated with the scaling factor by which the benchmark results should be multiplied. To use MTM scaling, leave this column unpopulated.

See the ERS 10.2 Release notes for further information.

column namenullabletype

这些都是完整的代码中提取,但我认为这应该是足够的人来帮助我。

谢谢!

2011-05-18

Freddie

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个Java格式化XML工具,同时会区分注释: ```java import java.util.Stack; public class XmlFormatter { private static final String INDENT = " "; public static String format(String xml) { StringBuilder result = new StringBuilder(); Stack<String> stack = new Stack<>(); int level = 0; boolean inTag = false; boolean inComment = false; boolean inCDATA = false; boolean inProcessingInstruction = false; boolean inAttributeValue = false; char currentQuote = '"'; boolean inEntity = false; StringBuilder currentWord = new StringBuilder(); for (int i = 0; i < xml.length(); i++) { char c = xml.charAt(i); if (inComment) { currentWord.append(c); if (currentWord.toString().endsWith("*/")) { result.append(currentWord); currentWord = new StringBuilder(); inComment = false; } } else if (inCDATA) { currentWord.append(c); if (currentWord.toString().endsWith("]]>")) { result.append(currentWord); currentWord = new StringBuilder(); inCDATA = false; } } else if (inProcessingInstruction) { currentWord.append(c); if (c == '?' && currentWord.toString().endsWith("?>")) { result.append(currentWord); currentWord = new StringBuilder(); inProcessingInstruction = false; inTag = false; } } else if (inAttributeValue) { currentWord.append(c); if (c == currentQuote) { result.append(currentWord); currentWord = new StringBuilder(); inAttributeValue = false; } } else if (inEntity) { currentWord.append(c); if (c == ';') { result.append(currentWord); currentWord = new StringBuilder(); inEntity = false; } } else if (inTag) { if (c == '>') { currentWord.append(c); result.append(currentWord); if (currentWord.toString().startsWith("</")) { level--; } else if (!currentWord.toString().startsWith("<?")) { stack.push(currentWord.toString()); level++; } currentWord = new StringBuilder(); inTag = false; } else if (c == '"' || c == '\'') { currentWord.append(c); inAttributeValue = true; currentQuote = c; } else { currentWord.append(c); } } else if (c == '<') { if (currentWord.length() > 0) { result.append(indent(level) + currentWord); currentWord = new StringBuilder(); } currentWord.append(c); inTag = true; if (xml.charAt(i + 1) == '?') { inProcessingInstruction = true; } else if (xml.charAt(i + 1) == '!') { if (xml.charAt(i + 2) == '-' && xml.charAt(i + 3) == '-') { inComment = true; } else if (xml.charAt(i + 2) == '[' && xml.charAt(i + 3) == 'C' && xml.charAt(i + 4) == 'D' && xml.charAt(i + 5) == 'A' && xml.charAt(i + 6) == 'T' && xml.charAt(i + 7) == 'A' && xml.charAt(i + 8) == '[') { inCDATA = true; } } } else { currentWord.append(c); if (c == '&') { inEntity = true; } } } return result.toString(); } private static String indent(int level) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < level; i++) { sb.append(INDENT); } return sb.toString(); } } ``` 使用方法: ```java String xml = "<xml><foo>bar</foo><!-- this is a comment --></xml>"; String formattedXml = XmlFormatter.format(xml); System.out.println(formattedXml); ``` 输出结果: ``` <xml> <foo> bar </foo> <!-- this is a comment --> </xml> ``` 其中,注释会被识别为 `<!-- ... -->` 的格式,并在格式化后保留其原有位置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值