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—Writing to an XML file

  1. We want to be able to write an XML file. To write the XML file, we will follow the same idea. Add the following function in the Layer class:
    public function toXMLNode() : Xml
    {
    var nXml = Xml.createElement("layer");
    nXml.set("id", this.id);
    return nXml;
    }
    
  2. Now, add the following code in the Page class:
    public function toXMLFile(path : String)
    {
    var xmlDoc = Xml.createDocument();
    var pageNode = Xml.createElement("page");
    pageNode.set("name", this.name);
    xmlDoc.addChild(pageNode);
    for(l in layers)
    {
    pageNode.addChild(l.toXMLNode());
    }
    neko.io.File.write(path, false).writeString(xmlDoc.toString());
    }
    

You can now save a page and all its layers by calling toXMLFile.

What just happened?

We have created a simple of the ...

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