I have an XSD element
<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>
Type author:
<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>
Base 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>
Type Id:
<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>
The problem is that I always have an ID but sometimes it may happen that AuthorName is null.
In that situation what I get is:
<author id="111111"/>
What I want to get is:
<author id="111111"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true"/>
My actual state makes problems with schema compatibility. Is it possible to do the thing I want without changing XSD model? Splitting Author into AuthorName and AuthorId isn't backward compatible and will require rewriting pretty big application.
Additional info (I'm not quite sure what is useful and what isn't): application is in J2E, I'm binding xsd with JAXB and I am generating classes using XJC.
Generated class Author:
@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
}