ho ottenuto questo struttura XML:Come gestire JAXB ComplexType con dati MixedContent?
<Tax>
<Money currency="USD">0.00</Money>
<Description xml:lang="en">
17.5% Non-Recoverable
<ShortName>vatspecial</ShortName>
</Description>
</Tax>
noti che Description
nodo ha MixedContent
(composta con testo e XML) e questa è la parte XSD
quanto riguarda Description
nodo:
<xsd:complexType name="TaxDescriptionType">
<xsd:sequence>
<xsd:element name="ShortName" type="xsd:string" />
</xsd:sequence>
<xsd:attribute ref="xml:lang" />
</xsd:complexType>
A questo punto tutto è a posto, XJC
restituisce il generat classi cati come questo riguardo TaxDescriptionType
:
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>
* <complexType name="TaxDescriptionType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="ShortName" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* <attribute ref="{http://www.w3.org/XML/1998/namespace}lang"/>
* </restriction>
* </complexContent>
* </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;
}
}
poi, con quanto sopra class
sono in grado di risolvere con gli elementi di questo tipo:
taxDescriptionType.setLang("en");
taxDescriptionType.setShortName("vatspecial");
/* missing value: 17.5% Non-Recoverable */
Ma il problema è che ho Impossibile trovare un modo per get
o set
il 17.5% Non-Recoverable
testo del MixedContent-ComplexType
dall'esempio XML
precedente.
Questo è quello che ho provato e non funziona:
- Usato
mixed="true"
attributo in questo modo:
<xsd:complexType name="TaxDescriptionType" mixed="true">
(credo XJC è ignorando la l attributo ast)
Facendo qualche ricerca, ho trovato questo:
JAXB XJC compiler disregarding mixed=true on XML Schema documents
Ma non sono sicuro se questo è il modo per risolvere questo problema. Una delle risposte ha detto che questo è un bug e l'altro mostra un codice che trasforma il MixedContent
in un List<Serializable>
e forse la situazione successivo sarà su come affrontare questo:
taxDescriptionType.getContent().add(Serializable element);
(E io davvero non so come trattare con un elemento Serializable
)
Il parametro di tipo 'Serializable' di' List' è significativo? –