This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes formatted XML Ouput Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "formatted XML Ouput" Watch "formatted XML Ouput" New topic
Author

formatted XML Ouput

Holger Prause
Ranch Hand

Joined: Oct 09, 2000
Posts: 47

Hi
I have the following XML File
<root>
<TAG>some value</TAG>
<TAG>another value</TAG>
</root>
the i wrote a XSLT Script

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="/root">
<NEWTAG><xsl:value-of select="TAG"</NEWTAG>
<xsl:foreach/>
</xsl:template >
</xsl:stylesheet>

The ouput is
<NEWTAG>some value</NEWTAG><NEWTAG>another value</NEWTAG>
The formation get lost.
this is for the XML Parser ok - but for Humand its really hard to read when ther are more TAGS - the will be written all in one line
but i want the output to be
<NEWTAG>some value</NEWTAG>
<NEWTAG>another value</NEWTAG>/pre>

how ca i do that ?
by the way , if i use DOM and Java to create new elements the ouput is allright -but this has nothing to do with my question i think
Bye,
Holger
[This message has been edited by Holger Prause (edited January 18, 2001).]
[This message has been edited by Holger Prause (edited January 18, 2001).]
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
How 'bout if you insert an empty <BR/> or a <p/> element just before <xsl:foreach/> ?? I am assuming the output type is HTML/XHTML and not an XML, since if it were to be an XML, that's how it is actually stored. There may/may not be any linebreaks!

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java2 Platform.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Holger Prause
Ranch Hand

Joined: Oct 09, 2000
Posts: 47
the ouput Type is XML
is ther really no possebility to print XML formatted out ?
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
You might have to write a small utility yourself to do this.
Since XML is data representation, formatting has no scope inside the XML document. All whitespaces that do not belong to any element context are ignored making the entire document a cryptic stream of tightly bound tag sequence!.... that's the way it is


------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java2 Platform.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
On a related note, several browsers display XML documents with nice formatting. IE 5.5 onwards has built in XML support so that you can even drill-up and drill-down various levels of nesting. That's what I use to inspect large XML documents.
Ofcourse, if you're in side a program and want to inspect an XML stream, then the situation is different.

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java2 Platform.
Holger Prause
Ranch Hand

Joined: Oct 09, 2000
Posts: 47
Ok thx for your answers -

>since XML is data representation, formatting has no scope inside >the XML document. All whitespaces that do not belong to any >element context are
>ignored making the entire document a cryptic >stream of tightly bound tag sequence!.... that's the way it is
Ok i understand.Thank for your explanation.
>On a related note, several browsers display XML documents with >nice formatting. IE 5.5 onwards has built in XML support so that >you can even drill-up
> and drill-down various levels of nesting. >That's what I use to inspect large XML documents.
Thx for the tip i'll use vmware and explorer to view the code

bye,
Holger
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: formatted XML Ouput