栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

符号已定义。使用JAXB属性解决冲突

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

符号已定义。使用JAXB属性解决冲突

让我问一下这一行:

<xs:element ref="Symbol"/>

是在yahoo.xsd中定义的符号,还是在同一xsd文件中本地定义的符号?

我将尝试推断一些事实。

我假设您有两个XSD:

yahoo.xsd
some.xsd
(您的帖子中的第一个)。我非常有信心在中定义“符号”类型,
some.xsd
而不是中定义
yahoo.xsd
。如果不是这样,我希望有一些名称空间前缀(“
yahoo:Symbol”?)。

现在,您的some.xsd看起来是否类似于此:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" >    <!-- It's not important right now: -->    <!--<xs:import namespace="http://www.yahooapis.com/v1/base.rng" schemaLocation="yahoo.xsd"/>-->    <!-- declaration you omitted in your post, it's only example -->    <xs:element name="Symbol">        <xs:simpleType> <xs:restriction base="xs:integer">   <xs:minInclusive value="0"/>   <xs:maxInclusive value="100"/> </xs:restriction>        </xs:simpleType>    </xs:element>    <xs:element name="quote">        <xs:complexType>          <xs:sequence>   <xs:element ref="Symbol"/>          </xs:sequence>          <xs:attribute name="symbol" use="required" type="xs:NCName"/>        </xs:complexType>    </xs:element></xs:schema>

如果我说的是真的,那么您的jaxb绑定应如下所示:

<bindings xmlns="http://java.sun.com/xml/ns/jaxb"      xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"      xmlns:xs="http://www.w3.org/2001/XMLSchema"      version="2.1">    <bindings schemaLocation="some.xsd"> <!-- not yahoo.xsd -->        <bindings node="//xs:element[@name='quote']/xs:complexType/xs:sequence/xs:element[@ref='Symbol']"> <property name="SymbolAttribute" />        </bindings>    </bindings></bindings>

并生成的java类将是:

@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name = "", propOrder = {    "symbolAttribute"})@XmlRootElement(name = "quote")public class Quote {    @XmlElement(name = "Symbol")    protected int symbolAttribute;    @XmlAttribute(name = "symbol", required = true)    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)    @XmlSchemaType(name = "NCName")    protected String symbol;    ....


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/431219.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号