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

  • Home
  • SEARCH
  • 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 7848507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:13:45+00:00 2026-06-02T18:13:45+00:00

I want to have the following XML <doc> <items> <item /> <item /> <item

  • 0

I want to have the following XML

<doc>
   <items>
      <item />
      <item />
      <item />
   </items>
   <things>
      <thing />
      <thing />
      <thing />
   </things>
</doc>

The schema would be something like

<schema>
   <element name="doc">
      <complexType>
          <all>
              <element name="items" minOccurs="1">
                  <complexType>
                       <sequence>
                           <element name="item" minoccurs="0" maxoccurs="unbounded" />
                       </sequence>
                  </complexType>
              </element>
              <element name="things" minOccurs="1">
                  <complexType>
                       <sequence>
                           <element name="thing" minoccurs="0" maxoccurs="unbounded" />
                       </sequence>
                  </complexType>
              </element>
          </all>
      /<complexType>
   </element>
</schema>

Now with JAXB it creates a class called Doc which would have an Items type which has an Item. Therefor to add the first element I have to do this.

Doc doc = new Doc();
Items items = new Items();
items.getItem().add(new Item());
doc.setItems(items);

I would like to be able to do the following instead:

Doc doc = new Doc();
doc.getItems().add(new Item());

Or even better:

Doc doc = new Doc();
doc.addItem(new Item());

Anyway of doing this through JAXB bindings?

  • 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-02T18:13:48+00:00Added an answer on June 2, 2026 at 6:13 pm

    Per the comment by nsfyn55, there does not seem to be any way to do this with bindings.

    However, if you were using JAXB annoations, you could do:

    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Doc {
        @XmlElementWrapper(name = "items")
        @XmlElement(name="item")
        List<Item> items = new ArrayList<Item>();
    
        public void addItem(Item item) {
            this.items.add(item);
        }
    
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following xml and I want to fetch the value of node which
I have following xml as a response to a service not i want to
I have the following XML and I want to process it so that I
I have the following xml format that i want to bind it through a
I have the following XML <title> This is a <highlight>test</highlight> thanks. </title> and want
I have the following xml <rss> <channel> <item><title><![CDATA[bla]]></title><description><![CDATA[desc1]]></description><link>blah</link></item> <item><title><![CDATA[bleh]]></title><description><![CDATA[desc2]]></description><link>blahhh</link></item> </rss> </channel> I want to
Let's say I have the following XML: <Account> <AccountExpirationDate>6/1/2009</AccountExpirationDate> </Account> I want to use
I have XML in the following form that I want to parse with PHP
I have XML in the following format which I want to reformat: <blocks> <!--
I have the following xml file and want to parse it into an .aspx

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.