Accessing XSD type properties
For some XML element properties, Gosu provides access directly from the XML element even though the actual implementation internally is on the backing type instance. If an element is not an XSD-based element, you can access the properties directly, such as element.Children.
However, if you use an XSD type, you must prefix the property name with a dollar sign ($). This convention prevents ambiguity between properties defined on the XSD type and on the type instance that backs that type. For example, suppose the XSD defines an element’s child element named Children. There would unfortunately be two similar properties with the same name. Gosu prevents ambiguity by requiring properties to have a dollar-sign prefix if and only if the element is XSD-based:
- To access the child elements of an XSD-based element, use the syntax
element.$Children. - To access a custom child element named
Childrenthat the XSD defines, use the syntaxelement.Children. This name is not recommended because of the ambiguity, but Gosu can access this element correctly. You may not have control over the XSD format that you are using, so Gosu must disambiguate them.
Notes about this convention:
- This convention only applies to properties defined on XSD-based types.
- It does not apply to methods.
- It does not apply to non-XSD-based XML elements.
For example, suppose you use the root class XmlElement directly with no XSD to manipulate an untyped graph of XML nodes. In that case, you can omit the dollar sign because the property names are not ambiguous. There are no XSD types, so there is no overlap in namespace.
This requirement affects the following type instance property names that appear on an XML element, listed with their dollar sign prefix:
$Attributes$Class$Children$Namespace$NamespaceContext$Comment$QName$Text$TypeInstance$SimpleValue$Value– Only for elements with an XSD-defined simple content$Nil– Only for XSD-defined nillable elements
XmlElement element directly, not a subclass, the object is not an XSD type. The new object is an untyped node that uses the default type instance, which is an instance of the type AnyType. In such cases, there is no dollar sign prefix because there is no ambiguity between properties that are part of the type instance and properties on the XSD type.See also
