Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: is this a bug in JAXB or a problem of me?

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry is this a bug in JAXB or a problem of me?

    Hi

    There is a problem that keeps puzzling me. I tried to google to find the reason and there is just none.
    Therefore, I am not sure if somebody might know.

    Say I have a schema like the following,

            <xs:element name="api">
              <xs:complexType>
                <xs:choice maxOccurs="unbounded">  <--------
                  <xs:element ref="a" minOccurs="1" />
                  <xs:element ref="b" minOccurs="1" />
                  <xs:element ref="c" minOccurs="1" />

    CASE1: When the line pointed by the arrow is like

            <xs:choice maxOccurs="unbounded">

    JAXB "xjc -p SomePackageName -d . ...." would generate a variable in Api.java such as

            protected List<Object> aOrBOrC;

    CASE2: However, if I change it to

            <xs:choice maxOccurs="1">

    JAXB generates

            protected A a;
            protected B b;
            protected C c;

    My question is in CASE1, how do I retrieve the value of A, B, and C individually since it is only given
    ONE variable although its a list of them. aOrBOrC can only be either a, b or c. What if my instance of
    the xml contains values for all a, b, and c.
    I would expect xjc to generate something like the following for CASE1.

            protected List<A> a;
            protected List<B> b;
            protected List<C> c;


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: is this a bug in JAXB or a problem of me?

    I'm going to speculate and say: what does this produce:
    <xs:choice maxOccurs="1">
                  <xs:element ref="a" maxOccurs="unbounded" />
                  <xs:element ref="b" maxOccurs="unbounded" />
                  <xs:element ref="c" maxOccurs="unbounded" />
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: is this a bug in JAXB or a problem of me?

    This produce

     protected List<A> a;
     protected List<B> b;
     protected List<C> c;

    But as soon as
     <xs:choice maxOccurs="unbounded">
          <xs:element ref="a" maxOccurs="unbounded" />
          <xs:element ref="b" maxOccurs="unbounded" />
          <xs:element ref="c" maxOccurs="unbounded" />
     </xs:choice>

    it generates
    protected List<Object> aOrBOrC;

    I thought the <xs:choice maxOccurs="unbounded"> means I can have as many a b and c and in different order. Therefore, one variable aOrBOrC is not enough. Pls let me know what do I miss? Tx

  4. #4
    Junior Member
    Join Date
    May 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: is this a bug in JAXB or a problem of me?

    I think I know how to retrieve the a, b, and c individually,

    It seems all the instances are stored in this one List<Object> aOrBOrC; and I simply
    need to loop through the list and use the instanceof to see if it belongs to a, b, or c .

Similar Threads

  1. Generating JAXB classes
    By javaexp in forum Other Programming Languages
    Replies: 0
    Last Post: November 11th, 2013, 12:20 AM
  2. JAXB
    By ashkrish in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 16th, 2013, 11:39 PM
  3. Regarding JAXB
    By Anbarasi in forum JDBC & Databases
    Replies: 2
    Last Post: August 31st, 2012, 12:33 PM
  4. Which tech to use JAXB or XSTREAM ?
    By tcstcs in forum Java Theory & Questions
    Replies: 0
    Last Post: November 7th, 2011, 01:33 AM
  5. How to parse an object to and from XML using JAXB
    By Json in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: January 20th, 2010, 03:42 AM

Tags for this Thread