jaxb - how to define XSD for a XML with optional element -


i have xml likethis

<datapoint>    <fieldname>somestring</fieldname>    <value>some string</value> </datapoint> <datapoint>    <fieldname>somestring</fieldname>    <value>some string</value> </datapoint> <datapoint>    <fieldname>somestring</fieldname>    <value>        <filename>some string</filename>    </value> </datapoint> 

i need define xsd xml. used value complex type . when use value complex type not able parse string value value in jaxb. getting object only. if declare value simple type(string) not able read filename.what should do..please help.

you mark xml element optional including minoccurs="0" in definition.


i used value complex type . when use value complex type not able parse string value value in jaxb

if define complex type need pass corresponding class unmarshal method:

datapoint datapoint = unmarshaller.unmarshal(xml, datapoint.class).getvalue(); 

you not need use class parameter if define global element complex type. if define global element references named complex type instance of jaxbelement<datapoint> back, , if define global element anonymous type instance of datapoint.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -