U.f.O
U.f.O

Reputation: 299

Arranging of elements in xml with the use of jaxb/java

How can I rearrange my xml elements from:

- <course>
  - <CourseType>
    - <GroupIndex>
         <index>1</index> 
         <professor>James</professor> 
      </GroupIndex>
      <classType>Lecture</classType> 
    </CourseType>
  <courseCode>3000</courseCode> 
 </course>

To:

- <course>
    <courseCode>3000</courseCode>
  - <CourseType>
      <classType>Lecture</classType>
    - <GroupIndex>
         <index>1</index> 
         <professor>James</professor> 
      </GroupIndex> 
    </CourseType> 
 </course>

It's about how to arrange them such that elements that cant be expanded will always be above those that can be expanded.

I'm using JAXB marshalling in java to convert my objects to produce the xml file.

Upvotes: 3

Views: 164

Answers (1)

Sean F
Sean F

Reputation: 2390

Using a proporder in the class you are unmarshalling should help with this issue

e.g.

@XmlType(propOrder = {
        "courseCode",
        "CourseType"
    })

note: when using a propOrder all elements in the object must be added to the propOrder.

Upvotes: 5

Related Questions