> -----Original Message----- > From: Ralf Steppacher [mailto:[EMAIL PROTECTED] > Sent: Wednesday, July 10, 2002 7:27 PM > To: [EMAIL PROTECTED] > Subject: Re: Serializer does not indent > > > Simon, > > > OutputProperties outputFormat = new OutputProperties(); > > outputFormat.setProperty(OutputKeys.METHOD, Method.XML); > > outputFormat.setProperty(OutputKeys.INDENT, "yes"); > > > outputFormat.setProperty(OutputProperties.S_KEY_INDENT_AMOUNT, "7"); > > Serializer serialiser = > > SerializerFactory.getSerializer(outputFormat.getProperties()); > > This has no effect for me. I replaced my code with yours and have the > very same results. > Following your advice I removed all whitespace between > elements from the > source filea and the one-whitespace-indention disappeard, too. > Normalizing the DOM has no effect. I tried to write to a > FileOutputStream instead of System.out but no change occured. > > > > Try putting > > <xsl:strip-space elements="*"/> > > at the top-level of your stylesheet > > Um, perhaps I should note that I am not trying to serialize a > stylesheet > but an arbitrary XML document. But that shouldn't make any > difference, > does it?
[from your later email] >What I want to do is constructing a DOM from a indented XML file, >add/delete elements via the DOM API and serialize the DOM to a file again. >Are there means to do that with Xalan? I think this is more of a parser issue. That is pretty much what I am doing, and is exactly why I suggested adding the <xsl:strip-space> tag in a stylesheet. The reason is that if your DOM tree nodes already contain whitespace (as they will if you have generated them by parsing a pretty-formatted xml document), then the indenter will *not* strip out your whitespace & replace it with its own indenting whitespace. Only if a node does not have whitespace already in it will indenting be applied. I map a pretty-formatted xml input via a stylesheet to a DOM then serialize it; without <xsl:strip-space>, the <xsl:copy-of> nodes in my stylesheet copy the whitespace too, which means that I don't get indenting. By putting <xsl:strip-space elements="*">, the output of the <xsl:copy-of> operation doesn't have whitespace and so indenting is applied. Now I presume that you aren't using stylesheets at all? It sounds like you are just parsing using Xerces, deleting nodes using xerces (or perhaps xpath?), then using the Xalan serializer to dump the DOM to disk? In this case you will need to find some equivalent to calling <xsl:strip-space elements="*">. From memory, isn't there a Node.normalizeSpace() method? I think this is what you want... Hope this helps, Simon PS: Joseph, thanks for the reference to the document http://xml.apache.org/xalan-j/usagepatterns.html#outputprops I hadn't noticed it existed! PPS: thanks to all the Xalan developers, it's a great piece of work!
