0

まず、commentType オブジェクトへの参照を含む XSD があります。

...
<xs:complexType>
    <xs:sequence>
        <xs:element name="entry" type="ref:commentType">
...

commentType は次のように記述されます (同じ XSD):

...
<xs:complexType name="commentType" mixed="true">
    <xs:annotation>
        <xs:documentation>Some text</xs:documentation>
    </xs:annotation>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:any/>
    </xs:sequence>
    <xs:attribute name="date" type="xs:dateTime" use="required"/>
    <xs:attribute name="type" use="optional" default="PRODUCT">
        <xs:simpleType>
            <xs:restriction base="xs:token">
                <xs:enumeration value="PRODUCT"/>
                <!--Several values-->
            </xs:restriction>
        </xs:simpleType>
    </xs:attribute>
</xs:complexType>
...

Jaxb を使用して解析している XML ファイルでは、エントリは別の XSD で定義されている opDetails オブジェクトを参照しています...

...
<entry date="2010-03-26T10:40:27Z" type="PRODUCT">
    <opDetails xmlns="http://path/to/opDetails">
        <!--Object properties-->
    </opDetails>
...

(わかりやすくするために名前と構造を簡略化しています)

質問:

私のコードでこの他のオブジェクトを正しくマップする方法は?

TinyElementImpl のリストである entry.getContent() があります。

明らかに、2つのxsdのクラスを生成し、TinyElementImplをopDetailsとしてキャストしようとすることはオプションではありません:)

4

1 に答える 1

0

私は答えを見つけた

unmarshall はノードでも機能します。 http://docs.oracle.com/javaee/5/api/javax/xml/bind/Unmarshaller.html

私のコード:

org.w3c.dom.Node nodeEntryContent = (org.w3c.dom.Node)entry.getContent().get(0);

JAXBContext ctx;
Unmarshaller um;
opDetails dOp = null;
try {
    ctx = JAXBContext.newInstance("package.of.opDetails.containing.xjc.generated.classes");
    um = ctx.createUnmarshaller();
    dOp = (opDetails)um.unmarshal(nodeEntryContent);
} catch (JAXBException e1) {
    System.out.println("XML parsing error" + e1.getMessage());
}
于 2012-12-12T14:42:59.977 に答える