Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between <a_element /> and <a_element xsi:nil="true" />?

Tags:

do you know if there's a difference between these tags on XML/XSD?

<a_element /> and <a_element xsi:nil="true"/> 

e.g:

<SpreadCurve>       <Index>3M</Index>       <IndexNumber>4587</IndexNumber>       <BusinessArea xsi:nil="true" /> </SpreadCurve>  and  <SpreadCurve>       <Index>3M</Index>       <IndexNumber>4587</IndexNumber>       <BusinessArea /> </SpreadCurve> 

Are these equivalent ?

If I have a XSD element:

<xsd:element name="BusinessArea" type="xsd:string"/> 

this means that it is by default xsi:nil="false". And this means it will not accept a null value for this element.

My doubt is, will it accept this one?

<BusinessArea /> 

What does this really mean to the XSD?

Best regards

like image 636
Dark Defender Avatar asked Sep 21 '10 13:09

Dark Defender


1 Answers

You get this as your XSD BusinessArea should be defined as nillable="true". Something like:

<xsd:element name="BusinessArea" nillable="true"> ..... </xsd:element>  

What this mean is that BusinessArea element can have null value i.e. empty.

And if element in XML doesn't contain any value then it must have attribute xsi:nil="true":

<BusinessArea xsi:nil="true" /> 

This should be invalid :

<BusinessArea /> 

Two examples you showed should not be equivalent.

Check this out for understanding xsi:nil and nillable:

http://www.zvon.org/xxl/XMLSchemaTutorial/Output/ser_over_st0.html

http://www.w3.org/TR/xmlschema-0/#Nils

like image 69
YoK Avatar answered Oct 22 '22 07:10

YoK