Jak radzić sobie z JAXB ComplexType z danymi MixedContent?

Mam tę strukturę XML:

<Tax>
  <Money currency="USD">0.00</Money>
  <Description xml:lang="en">
     17.5% Non-Recoverable
    <ShortName>vatspecial</ShortName>
  </Description>
</Tax>

Zauważ, żeDescription węzeł maMixedContent (składa się z tekstu i XML) a to jestXSD część dotyczącaDescription węzeł:

<xsd:complexType name="TaxDescriptionType">
  <xsd:sequence>
    <xsd:element name="ShortName" type="xsd:string" />
  </xsd:sequence>
  <xsd:attribute ref="xml:lang" />
</xsd:complexType>

W tym momencie wszystko jest w porządku,XJC wyświetla wygenerowane klasy, takie jak ta, dotycząceTaxDescriptionType:

package org.com.project;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

/**
 * <p>Java class for TaxDescriptionType complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="TaxDescriptionType">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="ShortName" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *       &lt;/sequence>
 *       &lt;attribute ref="{http://www.w3.org/XML/1998/namespace}lang"/>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TaxDescriptionType", propOrder = {
    "shortName"
})
public class TaxDescriptionType {

    @XmlElement(name = "ShortName", required = true)
    protected String shortName;
    @XmlAttribute(name = "lang", namespace = "http://www.w3.org/XML/1998/namespace")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlSchemaType(name = "NCName")
    protected String lang;

    /**
     * Gets the value of the shortName property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getShortName() {
        return shortName;
    }

    /**
     * Sets the value of the shortName property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setShortName(String value) {
        this.shortName = value;
    }

    /**
     * Gets the value of the lang property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getLang() {
        return lang;
    }

    /**
     * Sets the value of the lang property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setLang(String value) {
        this.lang = value;
    }

}

Następnie z powyższymclass Jestem w stanie obejść takie elementy:

taxDescriptionType.setLang("en");
taxDescriptionType.setShortName("vatspecial");
/* missing value: 17.5% Non-Recoverable */

Ale problem polega na tym, że nie mogę znaleźć drogiget lubset 17.5% Non-Recoverable tekstMixedContent-ComplexType z góryXML przykład.

To właśnie próbowałem i nie działa:

Używanymixed="true" atrybut taki jak ten:

<xsd:complexType name="TaxDescriptionType" mixed="true">

(Myślę, że XJC ignoruje ostatni atrybut)

Przeprowadzając jakieś badania, znalazłem to:

Kompilator JAXB XJC pomijając mieszane = prawda w dokumentach XML Schema

Ale nie jestem pewien, czy jest to sposób na rozwiązanie tego problemu. Jedna z odpowiedzi mówiła, że ​​jest to błąd, aw drugim pokazuje kod, który przekształcaMixedContent w aList<Serializable> i może następna sytuacja będzie dotyczyła tego, jak sobie z tym poradzić:

taxDescriptionType.getContent().add(Serializable element);

(I naprawdę nie wiem, jak sobie z tym poradzićSerializable element)

questionAnswers(2)

yourAnswerToTheQuestion