久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何處理帶有 MixedContent 數(shù)據(jù)的 JAXB ComplexType?

How to deal with JAXB ComplexType with MixedContent data?(如何處理帶有 MixedContent 數(shù)據(jù)的 JAXB ComplexType?)
本文介紹了如何處理帶有 MixedContent 數(shù)據(jù)的 JAXB ComplexType?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我得到了這個(gè) XML 結(jié)構(gòu):

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

注意 Description 節(jié)點(diǎn)有 MixedContent (由文本和 XML 組成) 這是 XSD 部分關(guān)于 Description 節(jié)點(diǎn):

Notice that Description node has MixedContent (composed with text and XML) and this is the XSD part regarding Description node:

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

此時(shí)一切正常,XJC 輸出與 TaxDescriptionType 類似的生成類:

Everything is ok at this point, XJC outputs the generated classes like this one regarding 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>
 * &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;
    }

}

然后,通過上面的 class 我可以使用以下元素:

Then, with the above class I am able to work around with the elements like this:

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

但問題是我找不到 getset 17.5% Non-Recoverable 文本的方法來自上述 XML 示例的 MixedContent-ComplexType.

But the problem is that I can't found a way to get or set the 17.5% Non-Recoverable text of the MixedContent-ComplexType from the above XML example.

這是我嘗試過的,但它不起作用:

  • 像這樣使用 mixed="true" 屬性:

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

(我認(rèn)為XJC忽略了最后一個(gè)屬性)

做了一些研究,我發(fā)現(xiàn)了這個(gè):

JAXB XJC 編譯器忽略 XML 上的混合 = true架構(gòu)文檔

但我不確定這是否是解決此問題的方法.其中一個(gè)答案說這是一個(gè)錯誤,而另一個(gè)答案顯示了將 MixedContent 轉(zhuǎn)換為 List 的代碼,也許下一個(gè)情況將是如何處理:

But I am not sure if this is the way to solve this. One of the answers said that this is a bug and in the other one shows a code that transforms the MixedContent into a List<Serializable> and maybe the next situation will be about how to deal with this:

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

(而且我真的不知道如何處理 Serializable 元素)

推薦答案

正如你提到的,你需要添加 mixed 屬性來表明你的類型支持混合內(nèi)容.如果沒有指定,您的 XML 內(nèi)容無效:

As you mentioned you need to add the mixed attribute to indicate that your type supports mixed content. Without this specified your XML content is invalid:

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

生成的 TaxDescriptionType 類將具有以下屬性.本質(zhì)上,這意味著所有非屬性內(nèi)容都將存儲在 List 中.這是必要的,因?yàn)槟枰环N機(jī)制來指示文本節(jié)點(diǎn)在元素內(nèi)容中的位置.

The generated TaxDescriptionType class will have the following property. Essentially this means that all of the non-attribute content will be stored in a List. This is necessary because you need a mechanism that indicates where the text nodes are wrt the element content.

@XmlElementRef(name = "ShortName", namespace = "http://www.example.org/schema", type = JAXBElement.class)
@XmlMixed
protected List<Serializable> content;

您將使用 String(表示文本節(jié)點(diǎn))和 JAXBElement(表示元素內(nèi)容)的實(shí)例填充此列表.

You will populate this list with instances of String (representing text nodes) and JAXBElement (representing element content).

交替

混合內(nèi)容通常會使生活變得比實(shí)際需要的更加復(fù)雜.如果可能的話,我會推薦一個(gè)替代的 XML 表示.

Mixed content generally makes life more complicated than it needs to be. If possible I would recommend an alternate XML representation.

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

或者

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

這篇關(guān)于如何處理帶有 MixedContent 數(shù)據(jù)的 JAXB ComplexType?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩一区二区av | 久久精品视频在线免费观看 | 黄色欧美 | 亚洲国产精品成人无久久精品 | 亚洲高清在线 | 国产成人精品一区二区三区视频 | 久久精品免费一区二区 | 国产传媒视频在线观看 | 国产丝袜av | av日韩在线播放 | 日韩精品久久久 | 国产在线视频一区 | 国产999精品久久久 午夜天堂精品久久久久 | 伊人91在线 | 国产视频第一页 | 亚洲精品视频免费 | 久久精品欧美电影 | 欧美三区在线观看 | 亚洲激精日韩激精欧美精品 | 日韩人体视频 | 亚洲国产成人av好男人在线观看 | 韩国av一区二区 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 亚洲成人免费 | 天天综合网7799精品 | 国产一区二区三区高清 | 国产高清视频一区 | 欧美久久久久久 | 欧美精品一区三区 | 免费精品在线视频 | 在线免费观看毛片 | 日本超碰 | 99久久精品免费看国产免费软件 | 日韩欧美国产精品一区二区三区 | 免费毛片网| 不卡一二区 | 亚洲国产精品久久 | 蜜臀久久 | 午夜网| 亚洲美女网站 | 国产在线精品一区二区三区 |