В настоящее время я использую следующий код для отступа 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-адрес и как он работает?
Спасибо! :)




Вы переопределяете свойство indent-amount по умолчанию, которое определено в пакете org.apache.xml.serializer. Это включает отступ (поскольку по умолчанию 0).
Output properties for XML, HTML, and text transformation output are defined in property files in the org.apache.xml.serializer package.
You can override the default value of these properties in your stylesheet by using the attributes of an xsl:output element. You can override the Xalan specific default settings as follows:
Declare the xalan namespace in your stylesheet element (xmlns:xalan = "http://xml.apache.org/xalan").
Use the namespace prefix you assign (for example, "xalan") to redefine properties of interest in the stylesheet xsl:output element (for example, xalan:indent-amount = "5"). The following stylesheet fragment declares the xalan namespace and sets indent-amount to 2:
<?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" xmlns:xalan = "http://xml.apache.org/xalan"> <xsl:output method = "xml" encoding = "UTF-8" indent = "yes" xalan:indent-amount = "2"/>
Вы можете найти больше на http://xml.apache.org/xalan-j/usagepatterns.html в главе Configuring serialization output properties.
Все это при условии, что ваш сериализатор специфичен для xalan