my dog learned polymorphism*
The moose likes XML and Related Technologies and the fly likes Setter method for element with maxOccurs= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Setter method for element with maxOccurs="unbounded"" Watch "Setter method for element with maxOccurs="unbounded"" New topic
Author

Setter method for element with maxOccurs="unbounded"

Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91
Hello All,

I was able to successfully generate classes from xsd. But, while using the generated classes for create a content tree and marshall it to xml, I faced problems. I am unable to find the setter method for the root element. Below is the xsd for which I faced problem. Please take a look at the maxOccurs="unbounded" line.


With the above xsd, XJC generated a class with InstallServiceType interface having getNewAccount() and inner interface NewAccount. But what it lacked is setNewAccount(NewAccount). Without this element, I cannot marshall a java object to xml.

But, when I removed the maxOccurs="unbounded", xjc created InstallServiceType with the setter method setNewAccount(..).

Is this the problem with JAXB or is it with my schema?
Any help or pointers is appreciated.

Thank you,
Kiran


------------<br />SCJP
Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91
I found the answer myself. The interface doesn't have a settter method, but it has a gettermethod as I said. The getter method returns a List. So, to set, we can use the getter method as below.



Where tmp is a new NewAccount() to be added.

Thanks anyway,
Kiran
J Latap
Greenhorn

Joined: Mar 13, 2012
Posts: 1
Kiran Kumar wrote:I found the answer myself. The interface doesn't have a settter method, but it has a gettermethod as I said. The getter method returns a List. So, to set, we can use the getter method as below.



Where tmp is a new NewAccount() to be added.

Thanks anyway,
Kiran


thanks. this is exactly what I'm looking for
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setter method for element with maxOccurs="unbounded"