I'm trying to marshal and unmarshal the following "attrName" and "attrType" XML-Elements into a single class. (At the moment I read the values individually and construct my objects after the unmarshalling in Java.)
<wrapper>
<someOtherElement>xxx</someOtherElement>
<attrName ref="a">xxx</attrName>
<attrName ref="b">xxx</attrName>
<attrName ref="c">xxx</attrName>
<attrType attrRef="a">xxx</attrType>
<attrType attrRef="b">xxx</attrType>
<someOtherElement>xxx</someOtherElement>
</wrapper>
The "ref" XML-Attribute is used to identify a attribute and as a reference for the "attrType" XML-Element. But the "attrType" XML-Element is optional and must not be there. There can not be a "attrType" XML-Element without a "attrName" XML-Element.
I need to generate a List of "attribute" objects of the class:
package example;
public class Attribute {
private String name;
private String ref;
private String type;
public String getName() {
return name;
}
public void setName(String name) {
this.name= name;
}
public String getRef() {
return ref;
}
public void setRef(String ref) {
this.ref= ref;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type= type;
}
}
I already found following relating question. But It didn't help me in finding a solution for my problem. The problem is to find all related attribute names and types to construct a Java object.
I'd be grateful for any tips or advice in the right direction. If I did not explained anything satisfactory, please don't hesitate to ask as English is not my native tongue.
PS: I know I could use a different XML structure and solve the problem easily. But that is not possible for me.