File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
java/org/hisrc/xml/bind/tests/addelement
resources/org/hisrc/xml/bind/tests/addelement Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .hisrc .xml .bind .tests .addelement ;
2+
3+ import java .util .LinkedList ;
4+ import java .util .List ;
5+
6+ import javax .xml .bind .JAXBContext ;
7+ import javax .xml .bind .JAXBException ;
8+ import javax .xml .bind .annotation .XmlAttribute ;
9+ import javax .xml .bind .annotation .XmlElement ;
10+ import javax .xml .bind .annotation .XmlRootElement ;
11+ import javax .xml .bind .annotation .XmlTransient ;
12+
13+ import org .junit .Assert ;
14+ import org .junit .Test ;
15+
16+ public class AddElementTest {
17+
18+ @ Test
19+ public void addsElement () throws JAXBException {
20+
21+ JAXBContext context = JAXBContext .newInstance (Element .class );
22+ final Element element = (Element ) context .createUnmarshaller ()
23+ .unmarshal (getClass ().getResource ("element.xml" ));
24+ Assert .assertEquals ("beta" , element .getChildren ().get (1 ).getValue ());
25+ }
26+
27+ @ XmlRootElement (name = "element" )
28+ public static class Element {
29+ private List <Element > children = new LinkedList <Element >();
30+
31+ @ XmlTransient
32+ public List <Element > getChildren () {
33+ return children ;
34+ }
35+
36+ @ XmlElement (name = "element" )
37+ public void setChild (Element child ) {
38+ this .children .add (child );
39+ }
40+
41+ private String value ;
42+
43+ @ XmlAttribute
44+ public String getValue () {
45+ return value ;
46+ }
47+
48+ public void setValue (String value ) {
49+ this .value = value ;
50+ }
51+ }
52+ }
Original file line number Diff line number Diff line change 1+ <element >
2+ <element value =" alpha" />
3+ <element value =" beta" />
4+ </element >
You can’t perform that action at this time.
0 commit comments