我正在尝试生成以下xml输出代码段:
<benefits>
<notes>benefits note</notes>
<detail xmlns:ns2="http://www.w3.org/1999/xhtml">
**<body>**
<p style="font-family:'Myriad Pro';text-decoration:none">Description 2</p>
**</body>**
</detail>
</benefits>
这是我的Xml带注释的类
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "descriptionType", propOrder = {
"notes",
"detail"
})
public class DescriptionType {
@XmlElement(required = true)
protected String notes;
@XmlJavaTypeAdapter(value=CDATAAdapter.class)
@XmlElement(required = true)
protected Object detail;
public String getNotes() {
return notes;
}
public void setNotes(String value) {
this.notes = value;
}
public Object getDetail() {
return detail;
}
public void setDetail(Object value) {
this.detail = value;
}
}
如果在编组之前放置断点并检查类DescriptionType的“detail”变量实例,则它包含以下内容
String type
"<?xml version="1.0" encoding="UTF-8" standalone="no"?><body xmlns="http://www.w3.org/1999/xhtml"><p style="font-family:'Myriad Pro'">Description 1</p>
</body>"
当我尝试编组回到xml时,我会在我的自定义适配器中转换为Document Element,如下所示:
Element e = DocumentBuilderFactory.newInstance().newDocumentBuilder().
parse(new ByteArrayInputStream(((String)s).getBytes())).getDocumentElement();
return e;
然后输出变为:
<benefits>
<notes>benefits note</notes>
<detail xmlns:ns2="http://www.w3.org/1999/xhtml">
<p style="font-family:'Myriad Pro';text-decoration:none">Description 2</p>
</detail>
</benefits>
问题是什么?如何保留标签? 非常感谢