Java netbeans jaxb marshaller不生成xsi:nil

Java netbeans jaxb marshaller不生成xsi:nil,java,jaxb,marshalling,xml-nil,Java,Jaxb,Marshalling,Xml Nil,我还有一个问题。我的XSD模式“searchevents.XSD”是: 及 类SearchEventType包括代码的下一部分: @XmlElement(name = "Code", nillable = true) protected StringType code; 当我执行封送处理时,如果我不初始化元素“Code”,我会得到下一个XML结构(这是可以的) 当我设置元素值和atribute时,我会得到下一个XML(可以): asdf 问题是当我设置属性而不设置值时。我得到下一个X

我还有一个问题。我的XSD模式“searchevents.XSD”是:

类SearchEventType包括代码的下一部分:

@XmlElement(name = "Code", nillable = true)
protected StringType code;
当我执行封送处理时,如果我不初始化元素“Code”,我会得到下一个XML结构(这是可以的)



当我设置元素值和atribute时,我会得到下一个XML(可以):


asdf
问题是当我设置属性而不设置值时。我得到下一个XML(这不好):


由于未设置值(我尝试放置null或空字符串(“”),因此我希望下一个XML结构:

<SearchEvents xmlns="http://company/searchevents.xsd">
  <Code return="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</SearchEvents>


为什么我没有得到这样的结果。我错过什么了吗

致意


Tomaz

您是否在不正常的部分设置“”或null?是的,我正在调用code.SetValue(null)或code.SetValue(“”)。我想我终于找到了解决方案:generateElementProperty不应该设置为“false”。在该类之后,SearchEventType被定义为:@xmlementref(name=“Code”,namespace=”“,type=JAXBElement.class,required=false)受保护的JAXBElement代码;。然后我调用JAXBElement变量的setNil属性。@torosg-你能把它作为答案吗?
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "StringType", propOrder = { "value" })

public class StringType {

  @XmlValue
  protected String value;
  @XmlAttribute(name = "return")
  protected Boolean _return;

  ...
@XmlElement(name = "Code", nillable = true)
protected StringType code;
<SearchEvents xmlns="http://company/searchevents.xsd">
   <Code xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</SearchEvents>
<SearchEvents xmlns="http://company/searchevents.xsd">
   <Code return="true">asdf</Code>
</SearchEvents>
<SearchEvents xmlns="http://company/searchevents.xsd">
  <Code return="true"/>
</SearchEvents>
<SearchEvents xmlns="http://company/searchevents.xsd">
  <Code return="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</SearchEvents>