O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

  1. First, create the Layer class as follows:
    class Layer
    {
    public var id : String;
    public function new()
    {}
    }
    
  2. Now create the Page class as follows:
    class Page
    {
    public var name : String;
    public var layers : List<Layer>;
    public function new()
    {
    }
    }
    
  3. 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;
    }
    
  4. As you can see, it is not yet complete. We ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required