[英]JAXB EclipseLink Moxy add template xml
i have problem with my jaxb EclipseLink implementation. 我的jaxb EclipseLink实现有问题。
Let's assume I have the following Entity ... 假设我有以下实体...
@XmlRootElement(name = GenericConfigEntity.XML_ROOT_TAG)
public class GenericConfigEntity {
private String name;
private String data;
private String version;
private String date;
private String template;
@XmlAttribute(name = GenericConfigEntity.XML_NAME)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement(name = GenericConfigEntity.XML_DATA)
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@XmlAttribute(name = GenericConfigEntity.XML_VERSION)
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
@XmlAttribute(name = GenericConfigEntity.XML_DATE)
public String getDate() {
return date;
}
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
}
The string 'template' contains xml data already let's say someting like this (in my real context it is a lot more and I do not want to create the entities for this). 字符串“ template”已经包含xml数据,可以说是这样(在我的真实上下文中,它还有很多,我不想为此创建实体)。
<Prozess name="xx" test="1">
<Debug system="test" />
</Prozess>
Now my question is if there is a way to integrate the template string into the marshalling process that someting like this is generated 现在我的问题是是否有一种方法可以将模板字符串集成到编组过程中,从而生成类似的东西
<conf name="xx" version="x" datum="xx">
<Prozess name="xx" test="1">
<Debug system="test" />
</Prozess>
<Data>
TextTextText
</Data>
</conf>
It is no solution to wrap the template in an tag because i am restricted to this layout. 将模板包装在标签中不是解决方案,因为我仅限于这种布局。
Also @XmlValue is no solution because I get an exception "all other elements have to be an attribute because one is marked as xmlvalue". @XmlValue也不是解决方案,因为我得到一个异常“所有其他元素都必须是一个属性,因为一个元素被标记为xmlvalue”。
I haven't used this myself yet, but I reckon you could use the @XmlAnyElement
in conjunction with a DomHandler
to implement such a mapping. 我自己还没有使用过,但是我认为您可以将
@XmlAnyElement
与DomHandler
结合使用以实现这种映射。 You can find a helpful example in the blog of MOXy's lead programmer here . 你可以在莫西的首席程序员的博客一个有用的例子在这里 。
I think you'd still have to make sure that the XML content in your template field has at least an opening and a closing tag, which serve to identify the DOM element during (un)marshalling. 我认为您仍然必须确保模板字段中的XML内容至少具有一个开始和结束标记,这些标记用于在(取消)编组期间标识DOM元素。 That tag may be arbitrary as required by you.
根据您的要求,该标签可以是任意的。 I guess you could just look for the first tag appearing in the string and try to match it against the end of the string.
我想您可能只是寻找字符串中出现的第一个标签,然后尝试将其与字符串末尾进行匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.