Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MinOccurs 0 and nillable true

Tags:

soap

wsdl

xml

xsd

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/> 
like image 212
SpongebobJunior Avatar asked Apr 20 '16 01:04

SpongebobJunior


People also ask

What does Nillable true mean in xsd?

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.

What does Nillable false mean?

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.

What is the meaning of minOccurs 0 in xsd?

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.

What does Nillable mean?

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.


2 Answers

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.

like image 107
Tim Biegeleisen Avatar answered Sep 23 '22 10:09

Tim Biegeleisen


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.

like image 42
IKriKan Avatar answered Sep 24 '22 10:09

IKriKan