File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Preserving empty elements in XMLSerializer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Preserving empty elements in XMLSerializer" Watch "Preserving empty elements in XMLSerializer" New topic
Author

Preserving empty elements in XMLSerializer

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi,
I am trying to serialize a DOM document into XML file using OutputFormat.

I like to have the empty text content tags like <name></name>. But the serializer writes like <name/>. Is there a way I can make it write it in the desired manner?

Below is the serializer & formatter classes -



Below method is what i use -


Sample xml output

Thank you!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
According to the XML standard, both forms are equivalent - no properly written XML processing program should notice the difference.

What problem are you trying to solve?

Bill
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Yes - I accept that.

I want the tags to be expanded so that the users shall come and edit the XML in a text format and enter the text content.

If it's <name/> then users have to modify it to <name>John</name>

If it's <name></name> then users have to just add John in between.

It's not a strict requirement but I like to give it that way.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Allowing users to edit XML in a text editor is also a design error. It isn't difficult for them to make the document non-well-formed. So give them a proper XML editor, and your empty-element problem will also cease to exist.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Okay... Thanks Billy and Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Preserving empty elements in XMLSerializer