XSD-based properties and types
The most powerful way to use XML in Gosu is to use an XSD that describes what is valid in your XML format. If you can use or generate an XSD for your XML data, it is strongly recommended that you use an XSD file. The name of each XSD file must include an .xsd extension in lowercase.
To tell Gosu to
load your XSD, put your XSD files in the same file hierarchy in the configuration module as Gosu classes,
organized in subdirectories by package. At the file system level, this
is the hierarchy of files starting at:
PolicyCenter/modules/configuration/gsrcFor
example, to load an XSD in the package mycompany.schemas,
put your XSD file at the path:
PolicyCenter/modules/configuration/gsrc/mycompany/schemasGosu creates new
types in the type system for element declarations in the XSD. Where appropriate,
Gosu creates properties on these types based on the names and structure
within the XSD. By using an XSD and the generated types and properties,
your XML-related code is significantly more readable. You can use natural
Gosu syntax to access attributes and child elements using the period
operator. For example, access a child element named ChildName on an element with code
like element.ChildName.
The new types are defined in a subpackage that matches the name of the XSD, except in lowercase
and with no .xsd suffix. For example, if the XSD is at the path
gsrc/example/MyTest.xsd and contains an element called
Address, the new element type is
example.mytest.Address
If you cannot use an XSD, you can use
the basic properties and methods of XmlElement
like element.Children
and element.getChild("ChildName").
Getting and setting values in this way is harder to understand than using
XML types and properties. This type of XML-related code that does not
use XSD types is not type-safe, so Gosu cannot perform type checking,
which can lead to run-time errors.
