我有一个dtd文件,我使用jaxb生成java类。
<!ELEMENT Conf (Node+) >
<!ELEMENT Node EMPTY >
<!ATTLIST Node Key CDATA #REQUIRED
Value CDATA #REQUIRED >
jaxb生成了这个。 Conf class:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"node"
})
@XmlRootElement(name = "Conf")
public class Conf {
@XmlElement(name = "Node", required = true)
protected List<Node> node;
节点类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "Node")
public class Node {
@XmlAttribute(name = "Key", required = true)
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
protected String key;
@XmlAttribute(name = "Value", required = true)
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
protected String value;
对我来说,Node类没有意义,我想改为使用地图:
public class Conf {
protected Map<String,String> map
}
我想我正在寻找XmlAdater,我读过javadocs但是我仍然有问题要理解它是如何工作的。