1

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 Text

MOXy は、これを w:t ではなく w:delInstrText にマーシャリングしています。これは、私が期待/希望するものであり、Java 6/リファレンス実装が行うことです。

スキーマから:

        <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>

FWIW、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 jarを使用しています:

        +- 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);

    }
}
4

1 に答える 1

1

注: 私は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

MOXy を JAXB プロバイダーとして有効にするためjaxb.propertiesに、パッケージ内で呼び出されるファイルを追加しました。org.docx4j.wml

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

デモ

以下は、問題を再現するために使用したデモ コードです。

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"/>
于 2012-11-06T11:10:44.287 に答える