考虑以下 xml:
<Config>
<Paths>
<Path reference="WS_License"/>
</Paths>
<Steps>
<Step id="WS_License" title="License Agreement" />
</Steps>
</Config>
以下 JAXB 类:
public class Path {
private String _reference;
public String getReference() {
return _reference;
}
@XmlAttribute
public void setReference( String reference ) {
_reference = reference;
}
}
和
public class Step {
private String _id;
private String _title;
public String getId() {
return _id;
}
@XmlAttribute
public void setId( String id ) {
_id = id;
}
public String getTitle() {
return _title;
}
@XmlAttribute
public void setTitle( String title ) {
_title = title;
}
}
我不想将 Path 对象中的引用存储为 String,而是将其保存为 Step 对象。这些对象之间的链接是引用和 id 属性。@XMLJavaTypeAdapter 属性是要走的路吗?谁能提供一个正确用法的例子?
谢谢!
编辑:
我也想对元素做同样的技术。
考虑以下 xml:
<Config>
<Step id="WS_License" title="License Agreement">
<DetailPanelReference reference="DP_License" />
</Step>
<DetailPanels>
<DetalPanel id="DP_License" title="License Agreement" />
</DetailPanels>
</Config>
以下 JAXB 类:
@XmlAccessorType(XmlAccessType.FIELD)
public class Step {
@XmlID
@XmlAttribute(name="id")
private String _id;
@XmlAttribute(name="title")
private String _title;
@XmlIDREF
@XmlElement(name="DetailPanelReference", type=DetailPanel.class)
private DetailPanel[] _detailPanels; //Doesn't seem to work
}
@XmlAccessorType(XmlAccessType.FIELD)
public class DetailPanel {
@XmlID
@XmlAttribute(name="id")
private String _id;
@XmlAttribute(name="title")
private String _title;
}
Step-object 中的属性 _detailPanels 为空,链接似乎不起作用。是否有任何选项可以创建链接而不创建仅包含对 DetailPanel 的引用的新 JAXB 对象?
再次感谢 : )!