Accessing the nillness of an element
XML elements can be nil, which is not the same as being null.
An element that is nil must have no child elements, but can have
attributes. Additionally, an XSD can define whether an element is nillable, meaning it
is allowed to be nil.
If an XSD-based element is nillable, the XmlElement object exposes a property
with the name $Nil. All non-XSD elements also have this property, but
in such cases it is called Nil (with no $ prefix).
$Nil
property, Gosu generates a deprecation warning.Setting this property on an element to true affects whether Gosu adds an
xsi:nil attribute to the element upon serialization. Getting this
property returns the state of that flag (true or
false).
Example
The following XSD contains defines an element that is nillable.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Element1" type="xsd:int" nillable="true"/>
</xsd:schema>
The following code demonstrates how to set the $Nil property of the element.
uses examples.pl.gosu.xml.myschema.Element1
var xml = new Element1()
xml.$Nil = true
xml.print()
This code prints the following:
<?xml version="1.0"?>
<Element1 xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
See also
