Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Preserving empty elements in XMLSerializer

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... Thanks Billy and Paul
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic