I have next problem. My XSD schema "searchevents.xsd" is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified"
targetNamespace="http://company/searchevents.xsd"
xmlns="http://company/searchevents.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="SearchEventType">
<xs:sequence>
<xs:element minOccurs="0" name="Code" nillable="true" type="StringType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="StringType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute default="false" name="return"
type="xs:boolean" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="SearchEvents" type="SearchEventType"/>
</xs:schema>
It can be seen that I have one element called "Code" which is type xs:string with nillable=true and atribute "return".
When I generate java objects from xsd shema I set binding parameter:
<globalBindings generateElementProperty="false">
StringType class was generated with next syntax:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "StringType", propOrder = { "value" })
public class StringType {
@XmlValue
protected String value;
@XmlAttribute(name = "return")
protected Boolean _return;
...
and
class SearchEventType includes next part of code:
@XmlElement(name = "Code", nillable = true)
protected StringType code;
When I perform marshaling, If I don't initialize the element "Code" I get next XML structure (which is OK)
<SearchEvents xmlns="http://company/searchevents.xsd">
<Code xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</SearchEvents>
When I set element value and atribute I get next XML (which is OK):
<SearchEvents xmlns="http://company/searchevents.xsd">
<Code return="true">asdf</Code>
</SearchEvents>
The problem is when I set attribute and I don't set value. I get next XML (which is NOT OK):
<SearchEvents xmlns="http://company/searchevents.xsd">
<Code return="true"/>
</SearchEvents>
Because value is not set (I try to put null or empty string ("")) I would expect next XML structure:
<SearchEvents xmlns="http://company/searchevents.xsd">
<Code return="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</SearchEvents>
Why I don't get such result. Did I miss something?
Best regards
Tomaz