私は、このXML構造だ:MixedContentデータでJAXB ComplexTypeを処理する方法は?
<xsd:complexType name="TaxDescriptionType">
<xsd:sequence>
<xsd:element name="ShortName" type="xsd:string" />
</xsd:sequence>
<xsd:attribute ref="xml:lang" />
</xsd:complexType>
:Description
ノードはMixedContent
(テキストやXMLで構成)を持っており、これはDescription
ノードに関する
XSD
一部であることを
<Tax>
<Money currency="USD">0.00</Money>
<Description xml:lang="en">
17.5% Non-Recoverable
<ShortName>vatspecial</ShortName>
</Description>
</Tax>
お知らせ
この時点ですべてが正常です。XJC
は、私はこのような要素を回避することができています上記class
と
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;
}
}
次に、::TaxDescriptionType
に関するこのようなEDクラス
taxDescriptionType.setLang("en");
taxDescriptionType.setShortName("vatspecial");
/* missing value: 17.5% Non-Recoverable */
しかし、問題は、I get
またはset
17.5% Non-Recoverable
のテキストMixedContent-ComplexType
の上記のXML
の例からの方法を見つけることができません。
これは私が試したものですし、それが働いていない:使用
mixed="true"
このような属性:
<xsd:complexType name="TaxDescriptionType" mixed="true">
(私はXJCだと思います私を無視するAST属性)
は、いくつかの研究を行う、私はこれが見つかりました:
JAXB XJC compiler disregarding mixed=true on XML Schema documents
をしかし、これはこの問題を解決するための方法である場合、私はわかりません。答えの一つは、これはバグで、他方でList<Serializable>
にMixedContent
を変換し、おそらく次のような状況は、これに対処する方法についてだろうコードが表示されていることを言った:
taxDescriptionType.getContent().add(Serializable element);
(そして、私は本当にあなたがあなたのタイプが混在したコンテンツをサポートすることを示すためにmixed
属性を追加する必要が述べたように)
'List'の' Serializable'型パラメータは重要ですか? –