我有一个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
}