1

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

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
torosg
  • 81
  • 1
  • 3
  • Are you setting "" or null in the part which is not ok? – atamanroman Sep 01 '11 at 07:47
  • 1
    Yes I'm calling code.SetValue(null) or code.SetValue(""). I think I finaly found solution: generateElementProperty should not be set to "false". After that class SearchEventType becomes defined as: @XmlElementRef(name = "Code", namespace = "http://company/searchevents.xsd", type = JAXBElement.class, required = false) protected JAXBElement code;. Then I call setNil property on JAXBElement variable. – torosg Sep 01 '11 at 14:24
  • @torosg - Can you post that as an answer? – bdoughan Sep 02 '11 at 19:12

0 Answers0