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/>
The nillable attribute can be defined on an xsd:element within an XML schema. It specifies that the xsi:nil attribute is valid for the element. If an XML schema has defined the nillable attribute as true, it is mapped as a required attribute and is included in the document, however, its values are nullified.
nillable="false" means you can't have the attribute xsi:nil="true". But you don't have this attribute so this won't make it invalid.
The minOccurs attribute specifies the minimum number of times that the element can occur. It can have a value of 0 or any positive integer. The maxOccurs attribute specifies the maximum number of times that the element can occur.
The nillable attribute specifies whether or not an explicit NULL value can be assigned to the element. True enables an instance of the element to have the NULL attribute set to true. The NULL attribute is defined as part of the XML Schema namespace for instances.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With