What is Shankh???


Shankh is a synonym for Conch Shell.So why that name for this blog?? My grandma used to say "When you put the conch shell to your ear, you hear the sound of ocean". Ignoring all scientific explanations to it, i would like this blog to bring you the sound of vast ocean of technology. Take a look

Some Random quotes


Innovation distinguishes between a leader and a follower. -Steve Jobs

It is not that i am smarter than others, i just persist with problems longer

Jaxb: Printing Xml with proper formatting

Ever wondered when we print xml, instead of printing it in single line can’t we print with proper formatting and indentation.  If you are using Jaxb then there is a  nice little trick in  to achieve that.


JAXBContext jc = JAXBContext.newInstance( "MyClass.class" );

Marshaller marshaller = jc.createMarshaller();

marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );

marshaller.marshal( <object_to_marshal>, System.out );

Share

4 Responses to “Jaxb: Printing Xml with proper formatting”

  1. Don Says:

    works like a treat

  2. Anish Sneh Says:

    Hi

    Thanks for the suggestion, however I’m facing an issue for some JAXBs it just prints the PI for XML not complete XML.

    Please suggest.

    – Anish Sneh

  3. admin Says:

    Anish, I didn’t see your comment earlier. It seems like you haven’t annotated the class variables properly (most likely @XmlElement). Have a look at this tutorial for learning about Jaxb annotations https://jaxb.dev.java.net/tutorial/

  4. nishanth Says:

    works really good .. very useful for logging..

Leave a Reply

Subscribe to Comments?



RECENTPOSTS

MOSTCOMMENTS

MYARCHIVE