Time for action – Reading from the XML file
We are going to create a function to read from an XML file. So, let's proceed step by step.
First, create the
Layer
class as follows:class Layer { public var id : String; public function new() {} }
Now create the
Page
class as follows:class Page { public var name : String; public var layers : List<Layer>; public function new() { } }
Now, let's create a function to create a page from an XML file. Add the following function to the
Page
class:public static function fromXMLFile(path : String) : Page { var nPage = new Page(); var xmlDoc = Xml.parse(neko.io.File.read(path, false).readAll().toString()); nPage.name = xmlDoc.firstElement().get("name"); return nPage; }
As you can see, it is not yet complete. We have to parse a layer from the XML file, so let's do it now. Add the following function in the
Layer
class:public static function fromXMLNode(node : Xml) { var nLayer : Layer; nLayer = new Layer...