• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating empty tags using JAXB.

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have to generate an xml using jaxb. In my xml many tags ar empty. Here I need to set empty string ("") for all the elements I need in the xml. Is there any way to create empty xml tags for all the elements without setting the value as empty string?

Thanks in advance.
 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any answers ??
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if you just leave null references?

Bill
 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The tag wont come if we didnt set blank string.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know much about JAXB but that seems like an extremely sensible design to me. Null produces no element, empty string produces empty element. When you're designing a data structure you do need to distinguish between null and non-null values. Apparently whatever is consuming the output of this JAXB instance didn't do that, and now you have to write an adapter to make up for that omission.
 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I need to put blnak string for all the empty tages?? :cry:
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could consider changing the code which processes the output of JAXB so that it handles non-existent elements better.
 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is fine, but for bix xmls i need to set all the tags with empty string, like

request.setVal1("");
request.setVal2("");
request.setVal3("");
request.setVal4("");
request.setVal5("");
request.setVal6"");
request.setVal7("");
request.setVal8("");
......
........
......
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me be clearer, then. Can you explain why it's a problem that an element (to use the standard XML terminology) is missing rather than empty?
 
Greenhorn
Posts: 4
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same issue while working with JAXB in a Jersey project, i found this article http://jaxb.java.net/tutorial/section_2_2_12_8-No-Value.html#No%20Value

Basically all you need to do is to add nillable = true as an attribute in your @XmlElement annotation, e.g. @XmlElement(nillable=true)
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even I tried to get this objective - "creating empty tags for the xsd elements using JAXB approach"

But though at the xsd, we specify nillable = "true" : It helps in getting the empty tags but it has got further description with title of the tag.
Is this below tag suggestable -
"<remarks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>" (here remarks is the tag which got created with no value, but some schema info is present)
 
reply
    Bookmark Topic Watch Topic
  • New Topic