Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:08:25+00:00 2026-06-06T19:08:25+00:00

I have the following xml format that i want to bind it through a

  • 0

I have the following xml format that i want to bind it through a POJO and using JAXB annotations. The XML format is the following:

 <datas>
   <data>apple<data>
   <data>banana<data>
   <data>orange<data>
 <datas>

And i’m trying to bind the data through the following POJO:

@XmlRootElement()
@XmlAccessorType(XmlAccessType.FIELD)
public class Datas {

  @XmlElement
  private List<String> data;

  //get/set methods

}

And also i try and this POJO:

@XmlRootElement()
@XmlAccessorType(XmlAccessType.FIELD)
public class Datas {

  @XmlElement
  private List<Data> datas;

  //get/set methods

}

//

@XmlRootElement()
@XmlAccessorType(XmlAccessType.FIELD)
public class Data{

  @XmlElement
  private String data;

  //get/set methods

}

In the first case it retrieves only the first data: apple. In the second case doesn’t retrieve anything. Could someone help me to provide the appropriate POJO and annotations in order to bind all data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:08:26+00:00Added an answer on June 6, 2026 at 7:08 pm

    You can do one of the following options:

    OPTION #1

    Datas

    package forum11311374;
    
    import java.util.List;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Datas {
    
      private List<String> data;
    
      //get/set methods
    
    }
    

    For More Information

    • http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html

    OPTION #2

    Datas

    package forum11311374;
    
    import java.util.List;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Datas {
    
      @XmlElement(name="data")
      private List<Data> datas;
    
      //get/set methods
    
    }
    

    Data

    package forum11311374;
    
    import javax.xml.bind.annotation.*;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Data{
    
      @XmlValue
      private String data;
    
      //get/set methods
    
    }
    

    For More Information

    • http://blog.bdoughan.com/2011/06/jaxb-and-complex-types-with-simple.html

    The following can be used with both options:

    input.xml/Ouput

    I have updated the XML document to contain the necessary closing tags. <data>apple</data> instead of <data>apple<data>.

    <datas>
       <data>apple</data>
       <data>banana</data>
       <data>orange</data>
     </datas>
    

    Demo

    package forum11311374;
    
    import java.io.File;
    import javax.xml.bind.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Datas.class);
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            File xml = new File("src/forum11311374/input.xml");
            Datas datas = (Datas) unmarshaller.unmarshal(xml);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(datas, System.out);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XML in the following format which I want to reformat: <blocks> <!--
I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
I want to send an xml document that i have created using jdom api.
I have the following requirement: In C#2.0, Given a device configuration in xml format
I have an xml file in the following format: <food> <desert> cake <desert> </food>
I have some (malformed DITA) XML in the following format: <dl> <dlentry><dt>BLARG</dt> <dd>BLARG Definition</dd>
I have following xml and I want to fetch the value of node which
I have following XML, and i wish to save its data in my SQL
I want XML in the following format: <configuration><!-- Only one configuration node --> <logging>...</logging><!--
I have XML in the following format: <Products> <Product name=MyProduct1> <Components> <Component name=MyComponent1> <Teams>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.