2013年12月10日星期二

The problem

JAXB marshaller
 This post last edited by linwu_2006_2006 on 2013-12-10 12:58:20
I want to generate the following xml structure, using JAXB, should I ask my class how to define and increase the label .



test


------ Solution ------------------------------- -------------
jaxb under the main floor of the familiar comment . For example the landlord can test

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;

@XmlRootElement
public class Hierarchy {

private String code;
private String value;
@XmlAttribute(name="Hierarchy_Code")//这个注解说明为一个属性
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@XmlValue//此注解时说明这是一个元素的值不会生成一个元素或属性只是值
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public static void main(String[] args) throws Exception {
JAXBContext context=JAXBContext.newInstance(Hierarchy.class);
Marshaller marshaller=context.createMarshaller();
Hierarchy h=new Hierarchy();
h.setCode("TEST");
h.setValue("测试用例");
marshaller.marshal(h, new File("a.xml"));
}
}

------ For reference only ----------------------------------- ----
the top, there are prawns know?
I just know that if a property Hierarchy_Code = "TEST"
So when the variable is defined only comment was : @ XmlAttribute can,
but do not know test The " test " how to display it. . .
------ For reference only -------------------------------------- -
urgent solution ! ! ! !
------ For reference only -------------------------------------- -
very grateful suciver, the company projects urgently needed , never used before . After a good look jaxb annotations.
now emergency first . Thank you ! ! !

没有评论:

发表评论