I am using XMLOutputter class for writing Document object’s contents into a xml file.
But i am facing below problem:
when i delete any child node, it creates blank line in Document object and while saving its contents into xml file, it displays blank line in xml file as well.
So it means that if i perform delete operation 10 time and saved its contents then there would be 10 blank lines in the xml file.
I went through the below links. These links suggest to use below api:
this link suggest:
XMLOutputter fmt = new XMLOutputter();
fmt.setTextTrim(true); //this would remove all spaces
fmt.setIndent(" "); // this will do indentation
fmt.setNewlines(true);
-
http://www.ibm.com/developerworks/xml/tutorials/xmljava/section5.html
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(new File(argv[0]));
XMLOutputter xo = new XMLOutputter();
xo.setTrimAllWhite(true);
xo.output(doc, System.out);
Can some one help me regarding this issue.
Thanks in Advance !!
Do you want to remove whitespace/blank lines, or do you want the output to be formatted nicely with correct indents etc.?
To get nice indenting use the ‘pretty’ format?
to strip all unnecessary whitespace use Format.getCompactFormat()
rolfl