Results 1 to 3 of 3
  1. #1
    BigBear is offline Member
    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    0

    Smile how to pretty print xml into file

    I generate xml by JAXB and I marshal it direct into file.
    Java Code:
    marshaller.marshal(Object JAXBElement, File Output);
    Everything is ok, but if I open file, whole code is in one line. I'd like to "pretty print", i'd like to get good readable xml file. How can I reach it? Thnx

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Use: Marshaller.JAXB_FORMATTED_OUTPUT

    Something like this:

    Java Code:
    Marshaller m = jc.createMarshaller();
    m.setProperty( [B]Marshaller.JAXB_FORMATTED_OUTPUT[/B], Boolean.TRUE);
    			
    /*OUTPUT TO FILE:*/
    File outputXmlFile = new File ("C:/temp/outputXmlFile.xml");
    OutputStream os = new FileOutputStream(outputXmlFile); 
    			
    m.marshal( foo, os);
    os.close();
    cheers!

  3. #3
    BigBear is offline Member
    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    0

Similar Threads

  1. pretty simple array question
    By 711groove in forum New To Java
    Replies: 8
    Last Post: 12-06-2009, 10:14 AM
  2. Unable to Print more than 1 File
    By satyam000 in forum Networking
    Replies: 1
    Last Post: 11-24-2009, 07:25 AM
  3. trying to print a text file.
    By IYIaster in forum New To Java
    Replies: 1
    Last Post: 10-12-2009, 06:55 PM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. Print a picture file
    By oli001 in forum New To Java
    Replies: 0
    Last Post: 11-26-2007, 01:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •