39

In my wsdl I have an element:

<xsd:element minOccurs="0" name="birthDate" nillable="true" type="xsd:dateTime"/>

I know that the nillable true allows null values does this means that it can allow xml empty tag? i.e

<birthDate/>
SpongebobJunior
  • 601
  • 1
  • 9
  • 24

2 Answers2

53

Setting nillable="true" means that the <birthDate> tag can appear as follows:

<birthDate xsi:nil="true"/>

However, since you also set minOccurs="0", you could also omit the <birthDate> tag completely from the XML and it would also still validate against your XSD.

Note that <birthDate/> or <birthDate></birthDate> is not considered null according to XSD rules.

Have a look at this great blog post for further reading.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • 10
    Setting nillable="true" does not allow you to write ``, it only allows you to write ``. Which probably explains why no-one actually uses the feature. – Michael Kay Apr 20 '16 at 07:44
  • 1
    @MichaelKay Thank you for correcting me and I apologize for the initial misinformation. – Tim Biegeleisen Apr 20 '16 at 08:23
1

Adding my view to above answers, A basic thing that many beginners don't know or take into consideration is binding the xsi variable with Schema Instance namespace.

Eg: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" [add this as a attribute anywhere in a xml opening tag].

The attribute prefix "xsi" in this case has to be bonded with the XML namespace "http://www.w3.org/2001/XMLSchema-instance". This binding can be done in any of the parent elements or in the root element itself, Where to do the binding depends on the scope for which you want the xsi to be available.

  • All the elements in nested to to declaration gets the same value
  • Even though you can use any name for binding the namespcae, for brevity its always recommended to use xsi for "http://www.w3.org/2001/XMLSchema-instance"

PS : I realized the whole importance of xml namespace bindings and prefixing attributes wherever required, when I struggled at work by staying back for 3 extra hours to understand, why my xml node is not getting validated by its xsd even in case of a nillable attribute in present in schema definition.

IKriKan
  • 1,069
  • 12
  • 12