Pretty print in what way? You can use XSL, of course, to make XML look however you want. Moving to XML forum. [ March 28, 2004: Message edited by: Thomas Paul ]
Pretty-printing into what media (to a web page or an XML file)? One way to achieve the former could be to use the XMLSerializer class from Xerces-J and hand it a custom Writer/OutputStream which encodes all special characters such as "<" and ">" into their HTML entity counterparts. Just an idea -- I really don't know how well this would work.
I want the xml, not the data in the xml, to be presented to standard out with line breaks, tabs, ... anything needed to make it read-able. Doesn't XSL only work on how the data in the xml is handled? I will checkout the XMLSerializer and see if that gives me what I want.
Please ignore post, I have no idea what I am talking about.
Originally posted by William Barnes: Ok. But does that help me solve my problem in anyway? Thanks.
It does, because while your XSL templates only copy what's in the source XML file, it produces an indented version of it if you plug a <xsl:output method="xml" indent="yes"/> on top of your stylesheet.
Ok, so I am running xalan from the command line (the one which comes with Websphere 4.0). My input xml is:
My template/stylesheet is:
And I get the values from the xml, not the xml, output to the screen. The output is actually the same as not having the line And if I change the output method to "html" I still get only the values from the input xml.
My output is always:
Any ideas about what I am doing wrong here? And yes I had to remove the ":" between "xml" and "output" to get rid of those damn smilies. Thanks. [ April 02, 2004: Message edited by: William Barnes ]
Please ignore post, I have no idea what I am talking about.
You must specify at least one <xsl:template> which uses the <xsl:copy-of> element to copy the source tree to the result tree as is, but with the indentation. Googling for "pretty print xml xsl" gives some examples.
Usually I google things, don't know why I didn't do it this time. That example was helpful, but there were not many others. Ok, so I have this working - it breaks up the xml - but the indentation still isn't working. Can this be a limitation with xalan? Do I need to try another XSL processor? Input xml:
xslt:
Output xml:
Thanks.
Please ignore post, I have no idea what I am talking about.
I think you should try other XSL engines. If you're driving the XSL transformation from Java code, you might also want to try Transformer#setOutputProperty(OutputKeys.INDENT, "yes") Also, if you can use Xerces-specific functionality, there's a handy class called XMLSerializer which produces nicely indented XML.