| Author |
Preserving empty elements in XMLSerializer
|
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
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: 12271
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
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: 16483
|
|
|
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: 1778
|
|
|
Okay... Thanks Billy and Paul
|
 |
 |
|
|
subject: Preserving empty elements in XMLSerializer
|
|
|