Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

writing xml : layout

Thread view: 
Tomba - 20 Dec 2005 14:57 GMT
hi all,

I'm writing an XML file from a DOM Document like this:

  Source source = new DOMSource(doc);
  Result result = new StreamResult(new File("settings.xml"));
  Transformer xformer = TransformerFactory.newInstance().newTransformer();
  xformer.transform(source, result);

While however it works, all XML tags are written on one line.

Is there any way I can change that behaviour so that there is
indentation and newlines in the file?

Thanks already
abigale_carson@yahoo.com - 20 Dec 2005 15:12 GMT
Check out this thread from comp.lang.java:

http://groups.google.com/group/comp.lang.java/browse_frm/thread/9045827b989a53f4
/2a8f942dd4a943a5?lnk=st&q=TransformerFactory+pretty-print&rnum=1&hl=en#2a8f942d
d4a943a5


Or, if it breaks,

http://linkfrog.net/dacn

Hope this helps,

Abigale
Chris Smith - 20 Dec 2005 16:00 GMT
> I'm writing an XML file from a DOM Document like this:
>
[quoted text clipped - 7 lines]
> Is there any way I can change that behaviour so that there is
> indentation and newlines in the file?

Not in the XML transformation APIs.  If you switch to Xerces instead of
using generic JAXP code, then Xerces has an option to pretty-print XML.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.