我有一個XSD元素一個值,XSI XSD元素:無= 「真」
<xsd:element name="author" type="cmd:Author" nillable="true">
<xsd:annotation>
<xsd:documentation>Contains author name and author id
</xsd:documentation>
</xsd:annotation>
</xsd:element>
類型作者:
<xsd:complexType name="Author">
<xsd:annotation>
<xsd:documentation>Author's name and id.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:extension base="cmd:AuthorName">
<xsd:attribute name="id" type="cmd:Id" use="optional">
<xsd:annotation>
<xsd:documentation>Author's Id
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
基地AUTHORNAME:
<xsd:simpleType name="AuthorName">
<xsd:annotation>
<xsd:documentation>Type defining author's name.
It may contain characters from AllowedChars
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="cmd:AllowedChars">
<xsd:maxLength value="112"/>
</xsd:restriction>
</xsd:simpleType>
類型標識:
<xsd:simpleType name="Id">
<xsd:annotation>
<xsd:documentation>Id
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{6}"/>
</xsd:restriction>
</xsd:simpleType>
問題是我總是有一個ID,但有時可能發生AuthorName爲空。
在那種情況下我得到的是:
<author id="111111"/>
我想要得到的是:
<author id="111111"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true"/>
我的實際情況,使問題與架構的兼容性。在不改變XSD模型的情況下可以做我想要的東西嗎?將Author拆分爲AuthorName和AuthorId不是向後兼容的,並且需要重寫相當大的應用程序。其他信息(我不太清楚什麼是有用的,什麼不是): 應用程序在J2E中,我使用JAXB綁定xsd,並且使用XJC生成類。
生成的類作者:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Author", propOrder = {
"value"
})
public class Author implements Serializable
{
@XmlValue
protected String value;
@XmlAttribute(name = "id")
protected String id;
//getters and setters
}