XML APIs (Java): how do I know if a document wants to be prettyprinted?

S

Simon Brooke

This relates to my earlier questions about namespaces...

When I use

javax.xml.transformer.Transformer.transform(
javax.xml.transform.Source, javax.xml.transform.Result)

then, if I pass a DOMResult object as the second argument, there's
nothing that I can see which I can get back from the DOMResult that
tells me that it wants the document to be pretty-printed. I can get back
the node which is the result of the transformation, and that node will
will in practice be either a document node or an element node. But I
can't see anything in either the DOM2 or DOM3 specifications for
Document, Element or Node which says whether they want to be pretty
printed - and, indeed, nor should there be, because a document is just a
bit of data and should be agnostic about its representation.

But the xsl:eek:utput directive takes 'indent="yes"' as a possible
attribute-value pair. An XSL transform has to be able to tell me that it
wants to be pretty printed, and it would seem it has to pass that back
to me in the Result or DOMResult specifications. I just don't see it.

Am I being stupid?
 
J

Joe Kesselman

Simon said:
then, if I pass a DOMResult object as the second argument, there's
nothing that I can see which I can get back from the DOMResult that
tells me that it wants the document to be pretty-printed.

Pretty-printing is the serializer's responsibiltiy. If you do a
transform to SAX or DOM rather than through the serializer, indent will
generally be ignored, because you're bypassing that portion of the
processor.
 
J

Joe Kesselman

(More generally: Most of the features of the xsl:eek:utput directive are
implemented by the serializer and apply only when outputting as a text
stream... or at most become annotations on the internal XML form, which
the serializer later acts upon. And the form of those annotations may or
may not be publicly exposed; check your particular XSLT processor's
documentation. For example: In some cases, Xalan used to pass hints to
its own serializers via a processing instruction which the serializer
acted on and discarded; I haven't checked whether that's still true or
whether those PIs are suppressed when outputting as DOM or SAX.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,255
Members
46,852
Latest member
CarlaDowle

Latest Threads

Top