我有以下XSD:
<!DOCTYPE xs:schema [
<!ELEMENT xs:schema (xs:element)*>
<!ATTLIST xs:schema
xmlns:xs CDATA #REQUIRED
attributeFormDefault CDATA #REQUIRED
elementFormDefault CDATA #REQUIRED>
<!ELEMENT xs:element (xs:complexType)*>
<!ATTLIST xs:element
maxOccurs CDATA #IMPLIED
minOccurs CDATA #IMPLIED
name CDATA #REQUIRED
type CDATA #IMPLIED>
<!ELEMENT xs:complexType (xs:sequence)*>
<!ATTLIST xs:complexType
mixed CDATA #IMPLIED>
<!ELEMENT xs:sequence (xs:element)*>
]>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="response">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="status"/>
<xs:element type="xs:byte" name="items_returned"/>
<xs:element type="xs:int" name="items_available"/>
<xs:element type="xs:byte" name="first_item_position"/>
<xs:element name="result">
<xs:complexType>
<xs:sequence>
<xs:element name="project" maxOccurs="unbounded" minOccurs="0">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element type="xs:short" name="id" minOccurs="0"/>
<xs:element type="xs:string" name="name" minOccurs="0"/>
<xs:element type="xs:string" name="url" minOccurs="0"/>
<xs:element type="xs:string" name="html_url" minOccurs="0"/>
<xs:element type="xs:dateTime" name="created_at" minOccurs="0"/>
<xs:element type="xs:dateTime" name="updated_at" minOccurs="0"/>
<xs:element type="xs:string" name="description" minOccurs="0"/>
<xs:element type="xs:anyURI" name="homepage_url" minOccurs="0"/>
<xs:element type="xs:string" name="download_url" minOccurs="0"/>
<xs:element type="xs:string" name="url_name" minOccurs="0"/>
<xs:element type="xs:string" name="medium_logo_url" minOccurs="0"/>
<xs:element type="xs:string" name="small_logo_url" minOccurs="0"/>
<xs:element type="xs:short" name="user_count" minOccurs="0"/>
<xs:element type="xs:float" name="average_rating" minOccurs="0"/>
<xs:element type="xs:short" name="rating_count" minOccurs="0"/>
<xs:element type="xs:byte" name="review_count" minOccurs="0"/>
<xs:element type="xs:int" name="analysis_id" minOccurs="0"/>
<xs:element name="tags" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="tag" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="licenses" minOccurs="0">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="license" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="nice_name"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="links" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="link" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="title"/>
<xs:element type="xs:string" name="url"/>
<xs:element type="xs:string" name="category"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
但是当我使用JAXB从它生成Java类时,它不会生成完整的类,而只会生成某个点之后的内容列表:
(Response
,Result
和Project
生成正确。但Project
的成员未生成)
@XmlMixed
protected List<Serializable> content;
和相应的吸气者:
/**
* Gets the value of the content property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the content property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getContent().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link Short }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link XMLGregorianCalendar }{@code >}
* {@link String }
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link Short }{@code >}
* {@link JAXBElement }{@code <}{@link Response.Result.Project.Links }{@code >}
* {@link JAXBElement }{@code <}{@link Short }{@code >}
* {@link JAXBElement }{@code <}{@link XMLGregorianCalendar }{@code >}
* {@link JAXBElement }{@code <}{@link Response.Result.Project.Tags }{@code >}
* {@link JAXBElement }{@code <}{@link Float }{@code >}
* {@link JAXBElement }{@code <}{@link Response.Result.Project.Licenses }{@code >}
* {@link JAXBElement }{@code <}{@link Byte }{@code >}
* {@link JAXBElement }{@code <}{@link Integer }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
*
*
*/
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
我想为每个元素设置一个变量,例如喜欢这个:
<xs:element type="xs:short" name="id" minOccurs="0"/>
或者我的XSD有问题吗?
答案 0 :(得分:2)
这是因为您的复杂类型有mixed="true"
。内容位于List
中,以便可以在任意两个元素之间添加混合文本内容。