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

在 XML 模式中指定 IDREF 的類型

specify type for IDREF in XML schema(在 XML 模式中指定 IDREF 的類型)
本文介紹了在 XML 模式中指定 IDREF 的類型的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 xjc 從 XML 模式生成 Java 對象.我想使用 IDREF 在文檔中多次引用同一個元素.我還想將 IDREF 引用的對象限制為特定類型.我想這樣做是出于模式驗證的目的,但也是為了在 Java 代碼中,引用的對象作為特定類型而不是 Object 類型返回.例如,假設我想要一個模式來描述以下內容:

I am generating Java objects from an XML schema using xjc. I would like to reference the same element multiple times within the document using IDREF. I would also like to constrain the objects referenced by IDREF to a specific type. I'd like to do this for the purposes of schema validation, but also so that in the Java code, the referenced object is returned as a specific type instead of type Object. For example, say I want a schema to describe the following:

<teams>
  <team id="team1">
    <coach>coachz</coach>
    <player>homestar</player>
    <player>marzipan</player>
    <player>strongsad</player>
    <player>strongbad</player>
  </team>

  <team id="team2">
    <coach>bubs</coach>
    <player>homesar</player>
    <player>thecheat</player>
    <player>poopsmith</player>
    <player>bubs</player>
  </team>

  <team id="allstars">
    <coach>poopsmith</coach>
    <player>coachz</player>
    <player>bubs</player>
    <player>kingoftown</player>
    <player>strongbad</player>
  </team>
</teams>

<people>
 <person id="coachz">Coach Z</person>
 <person id="homesar">Homesar</person>
 <person id="homestar">Homestar</person>
 <person id="strongbad">Strong Bad</person>
 <person id="strongsad">Strong Sad</person>
 <person id="marzipan">Marzipan</person>
 <person id="bubs">Bubs</person>
 <person id="kingoftown">King of Town</person>
 <person id="poopsmith">The Poopsmith</person>
 <person id="thecheat">The Cheat</person>
</people>

我可以這樣定義player:

<xs:element name="player" type="xs:IDREF" maxOccurs="unbounded"/>

但是在 Java 代碼中,當我嘗試檢索一個播放器時,它會作為類型對象返回,我必須將它轉換為一個人.那時,如果有人錯誤地引用了 Team 對象,我就有可能在驗證時發(fā)現(xiàn)的錯誤要處理.我想指定如下內容:

but then in the Java code, when I try to retrieve a player it will come back as type object, and I have to cast it to a person. At that point, if someone has mistakenly referenced a Team object, I have errors to deal with that could have been caught at validation. I want to specify something like this:

<xs:element name="player" type="xs:IDREF"reftype="person"maxOccurs="無界"/>

但據(jù)我所知,沒有辦法像我在此處使用人為屬性reftype"所做的那樣指定類型.這可以使用 IDREF 完成嗎?如果沒有,還有其他方法嗎?

But as far as I can tell, there is no way to specify a type as I have done here with the contrived attribute 'reftype'. Can this be done, using IDREF? If not, is there another method?

推薦答案

您可以簡單地將 baseType 綁定應用到您的 player 元素.比如:

You can simply apply baseType binding to your player element. Something like:

<jaxb:bindings node="xsd:element[@name='player']">
    <jaxb:property>
        <jaxb:baseType name="....Person"/>
    </jaxb:property>
</jaxb:bindings>

您可能需要為您的架構找出正確的綁定位置.

You may need to figure out the correct binding location for your schema.

我的代碼示例:

架構:

<xsd:complexType name="HJIII-53-A">
    <xsd:sequence>
        <xsd:element name="b" type="xsd:IDREF"/>
        <xsd:element name="b1" type="test:HJIII-53-B"/>
        <xsd:element name="c" type="xsd:IDREFS"/>
        <xsd:element name="c1" type="test:HJIII-53-C" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>

綁定:

<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
    <jaxb:globalBindings localScoping="toplevel">
        <jaxb:serializable/>
    </jaxb:globalBindings>
    <jaxb:bindings node="xsd:complexType[@name='HJIII-53-A']//xsd:element[@name='b']">
        <jaxb:property>
            <jaxb:baseType name="org.jvnet.hyperjaxb3.ejb.tests.issuesjpa2.HJIII53B"/>
        </jaxb:property>
    </jaxb:bindings>
    <jaxb:bindings node="xsd:complexType[@name='HJIII-53-A']//xsd:element[@name='c']">
        <jaxb:property>
            <jaxb:baseType name="org.jvnet.hyperjaxb3.ejb.tests.issuesjpa2.HJIII53C"/>
        </jaxb:property>
    </jaxb:bindings>
</jaxb:bindings>

生成的代碼:

@XmlElement(required = true, type = Object.class)
@XmlIDREF
@XmlSchemaType(name = "IDREF")
protected org.jvnet.hyperjaxb3.ejb.tests.issuesjpa2.HJIII53B b;
@XmlElement(required = true)
protected org.jvnet.hyperjaxb3.ejb.tests.issuesjpa2.HJIII53B b1;
@XmlList
@XmlElement(required = true, type = Object.class)
@XmlIDREF
protected List<org.jvnet.hyperjaxb3.ejb.tests.issuesjpa2.HJIII53C> c;
protected List<org.jvnet.hyperjaxb3.ejb.tests.issuesjpa2.HJIII53C> c1;

參見:https://svn.java.net/svn/hj3~svn/trunk/ejb/tests/issues-jpa2/src/main/resources/

這篇關于在 XML 模式中指定 IDREF 的類型的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(liá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(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美成人a | 97免费在线视频 | 91高清在线观看 | 91九色婷婷 | 9999国产精品欧美久久久久久 | 国产欧美日韩一区 | 午夜影院在线观看 | 成人在线免费电影 | 久久在线视频 | 91精品久久久久久久久中文字幕 | 亚洲高清免费观看 | 在线精品一区二区三区 | 九色91视频 | 日本在线视频一区二区 | 91精品国产高清久久久久久久久 | 亚洲九色 | 日韩在线观看一区 | 国产一区二区电影 | 欧美aⅴ片 | 国产午夜精品久久久 | 国产91视频一区二区 | 91精品国产91久久久久久吃药 | 国产精品不卡视频 | 亚洲精品日韩在线观看 | 草b视频 | 粉嫩一区二区三区国产精品 | 殴美成人在线视频 | 精品久久久久久久久久久久久久 | 成人午夜视频在线观看 | 99pao成人国产永久免费视频 | 毛色毛片免费看 | 久久久久一区二区 | 久久久久91| 中文日韩在线视频 | 欧美日韩亚洲国产综合 | 色网站在线免费观看 | 日韩欧美在 | 午夜寂寞网站 | 久久久精品一区 | 精品国产视频 | 一级毛片在线播放 |