Prev | Current Page 862 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


The following simple function processes an XML RTTI Document:
public static function parse(file)
{
var xml = neko.io.File.getContent(file);
var doc = Xml.parse(xml);
var parser = new haxe.rtti.XmlParser();
parser.process(doc.firstElement(), ???neko???); // set the platform you need
return parser.root;
}
The parser.process() function accepts an XML node as an argument and a platform name. The
processed structure is contained in the root field of the XmlParser instance and is an array of
TypeTree s. Each package is a container for subtypes and types can be Class , Enum , and Typedef
enumerations.
Chapter 16: haXe Advanced Topics
471
Another way to access RTTI information without loading an external XML file and available only for
class instances, is to use the haxe.rtti.Infos interface. A class that extends it is generated with a new
static field with name __rtti that contains the full XML notation for the current class.
The following example shows a class that implements Infos :
/**
* Test Class.


Pages:
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874