我正在尝试让docx4j支持MOXy作为它的JAXB实现。
我们差不多到了,见docx4j和MOXy
我的问题是我有一个班级
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "CT_Text", propOrder = {
"value"
})
@XmlRootElement(name = "t")
public class TextMOXy正在将其编组到w:delInstrText,而不是w:t,这正是我所期望/希望的,以及Java 6/ reference实现所做的事情。
来自模式
<xsd:element name="t" type="CT_Text">
<xsd:annotation>
<xsd:documentation>Text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="delInstrText" type="CT_Text">
<xsd:annotation>
<xsd:documentation>Deleted Field Code</xsd:documentation>
</xsd:annotation>
</xsd:element>ObjectFactory包含:
public Text createText() {
return new Text();
}
@XmlElementDecl(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "delInstrText", scope = R.class)
public JAXBElement<Text> createRDelInstrText(Text value) {
return new JAXBElement<Text>(_RDelInstrText_QNAME, Text.class, R.class, value);
}这与MOXy jars有关:
+- org.eclipse.persistence:org.eclipse.persistence.moxy:jar:2.4.1
| +- org.eclipse.persistence:org.eclipse.persistence.core:jar:2.4.1
| | \- org.eclipse.persistence:org.eclipse.persistence.asm:jar:3.3.1.v201206041142
| \- org.eclipse.persistence:org.eclipse.persistence.antlr:jar:3.2.0.v201206041011 更新:
下面是一个测试用例:
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import org.docx4j.wml.R;
import org.docx4j.wml.Text;
public class MOXyTest {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance("org.docx4j.wml");
// System.out.println(Version.getVersion());
// System.out.println(jc.getClass());
R run = new R();
Text text = new Text();
run.getContent().add(text);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(run, System.out);
}
}发布于 2012-11-06 11:10:44
备注:,我是EclipseLink JAXB (MOXy)的负责人,也是JAXB (JSR-222)专家组的成员。
更新
我们已经能够重现您在EclipseLink 2.4.1中看到的错误。我们无法在EclipseLink 2.4.2或2.5.0流中重现这个问题。我建议下载最新的2.4.2每晚构建并试用它:
我们仍在调查这个问题,以确保它是真正固定的。
原始答案
到目前为止,当使用MOXy作为JAXB提供程序时,我还无法重现您的问题的结果。你能提供一些额外的信息来帮助我重现你的用例吗?以下是我迄今所做的尝试:
Java模型
我从GitHub上的以下位置获取了Java模型:
jaxb.properties
我在jaxb.properties包中添加了一个名为org.docx4j.wml的文件,以启用作为JAXB提供程序的MOXy。
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactoryDemo
下面是我用来尝试再现问题的演示代码:
package org.docx4j.wml;
import javax.xml.bind.*;
import org.eclipse.persistence.Version;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance("org.docx4j.wml");
System.out.println(Version.getVersion());
System.out.println(jc.getClass());
Text text = new Text();
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(text, System.out);
}
}输出
下面是运行演示代码的输出。我看到正确的根元素t被编组出来,而不是问题中描述的delInstrText。
2.4.1
class org.eclipse.persistence.jaxb.JAXBContext
<?xml version="1.0" encoding="UTF-8"?>
<ns0:t xmlns:ns2="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:ns1="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:ns4="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:ns3="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:ns0="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:ns5="http://schemas.openxmlformats.org/officeDocument/2006/relationships"/>https://stackoverflow.com/questions/13242794
复制相似问题