让我问一下这一行:
<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; ....


