我目前正在使用以下代码来缩进XML:
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");这很好地压缩了代码,但是,我不确定http://xml.apache.org/xslt}indent-amount"在做什么。URL对于缩进是必不可少的。有人能解释一下这个URL的作用以及它是如何工作的吗?
谢谢!:)
发布于 2018-05-10 15:01:41
您正在重写默认属性indent-amount,它是在org.apache.xml.serializer包中定义的。这将启用缩进(因为默认值为0)。
org.apache.xml.serializer包中的属性文件中定义了XML、HTML和文本转换输出的输出属性。 您可以通过使用xsl:output元素的属性在样式表中覆盖这些属性的默认值。可以覆盖Xalan特定的默认设置,如下所示: 在样式表元素(xmlns:xalan="http://xml.apache.org/xalan")中声明xalan命名空间。 使用您指定的名称空间前缀(例如,"xalan")来重新定义样式表xsl:output元素中感兴趣的属性(例如,xalan:indent=“5”)。下面的样式表片段声明xalan命名空间并将缩进量设置为2:
您可以在http://xml.apache.org/xalan-j/usagepatterns.html的Configuring serialization output properties章节中找到更多信息。
所有这些假设序列化程序是xalan特定的
https://stackoverflow.com/questions/50275655
复制相似问题