Hello


I ran into some problems serializing my xml files using identation. 

Here is my file:

<?xml version="1.0" encoding="UTF-8"?><SigComBoxRequest>
<TransmissionInfo>
<MessageID>62c38851-529b-44b1-b290-4d8ed1c1d9cb</MessageID>
<Sender>LOCALENTITY</Sender>
<Receiver>LOCALENTITY</Receiver>
<MessageDate>2005-08-11T15:27:39</MessageDate>
</TransmissionInfo>
<Client>
<Identification>
<Id>120</Id>
<Name>PORCAVE - PRODUTOS ALIMENTARES  S.A</Name>
</Identification>
</Client>
<Client>
<Identification>
<Name>REFEITÃRIO</Name>

Setting the output properties:
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount";, "4");
, I get no indentation (the output is the same as the input)

I searched in JIRA and found that the CRLF are the problem:

Quoting Brian:
_______________________________________________
If you don't use a stylesheet there is no way to strip out the indentation in
your original XML because it looks like legitimate text to the processor. One
alternative would be to have a DTD that declares certain elements to contain
only other elements (for example) and the ContentHandler.ignorableWhitespace
(char ch[], int start, int len) calls happening in the processor would be
called and your indentation has a chance of being ignored and replaced by other
indentation. But I suspect that you don't want to change your XML and insert
information about DTD's, I think you just want to transform it into something
prettier.

The long and short of it is that I don't see a way to delete the current
indentation and insert new indentation without using a stylesheet like I've
listed earlier in this bug.
_______________________________________________

I dont have any whitespaces before line breaks, but I think problem is
similar). Using this xsl, the output is as expected:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
    xmlns:xalan="http://xml.apache.org/xalan";
    exclude-result-prefixes="xalan">
    <xsl:output encoding="iso-8859-1" indent="yes" xalan:indent-amount="4" 
method="xml" />
    <xsl:strip-space elements="*" />
    <xsl:template match="@*|comment()|processing-instruction()|text()|*">
        <xsl:copy>
            <xsl:apply-templates 
select="@*|comment()|processing-instruction()|text()|*"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

The <xsl:strip-space elements="*" /> makes the difference.


Now here comes my doubts... I want to serialize a dom and, for this
reason, the output is not indented. What is the best way to indent the
output?

1. Instead of using a Transformer(), use a Transformer(indent.xsl) - What
is the overhead of this?

2. Some other thing that I'm missing


Thank you.


PS: According to the number of occurrences I found in JIRA, shouldn't this
issue be in the FAQ?

-- 
Pedro Alves
[EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to