2

how do i translate a complexType in an .xsd file to a SimpleXML annotated class structure. here's an example that's been translated to JAXB using xjc.exe. not sure what the equivalent annotation would be for the Simple framework.

schema:

<xsd:element name="PaymentTxnID">
    <xsd:complexType>
        <xsd:simpleContent>
            <xsd:extension base="IDTYPE">
                <xsd:attribute name="useMacro" type="MACROTYPE"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
</xsd:element>

JAXB generated:

public static class PaymentTxnID {
    @XmlValue
    protected String value;
    @XmlAttribute(name = "useMacro")
    protected String useMacro;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getUseMacro() {
        return useMacro;
    }

    public void setUseMacro(String value) {
        this.useMacro = value;
    }
}

how can i represent complexTypes with Simple?

4

1 回答 1

2

看来@Text注释就是答案。在此处查看 javadoc 。该示例可在Blaise Doughan 的“将对象映射到简单内容”部分下的博客条目中找到。

简单的框架翻译:

public static class PaymentTxnID {
    @Text
    protected String value;
    @Attribute(name = "useMacro")
    protected String useMacro;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getUseMacro() {
        return useMacro;
    }

    public void setUseMacro(String value) {
        this.useMacro = value;
    }
}
于 2012-12-05T19:39:48.210 回答