Automatic creation of intermediary elements
If you use XSDs, whenever a property path appears in the left side of an assignment statement, Gosu creates intermediary elements to ensure that the assignment succeeds. This behavior provides a useful shortcut for typical XML coding. Use this feature to make your Gosu code more understandable.
Example
The following XSD contains defines multiple nested elements.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Element1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Child1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Child2" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
The following code demonstrates assignment to a nested element, in which an instance of the intermediary element is automatically created.
uses examples.pl.gosu.xml.myschema.Element1
uses examples.pl.gosu.xml.myschema.anonymous.elements.Element1_Child1
uses examples.pl.gosu.xml.myschema.anonymous.elements.Element1_Child1_Child2
var xml = new schema.Element1()
print("Before assignment: ${xml.Child1}")
xml.Child1.Child2 = 5 // Assignment of a value to Child2 automatically creates Child1.
print("After assignment: ${xml.Child1}")
This code prints the following:
Before assignment: null
After assignment: schema.anonymous.elements.Element1_Child1 instance