public function writeXml($filename)
    {
        $dom           = new DOMImplementation;
        $dtd           = $dom->createDocumentType('entity', '', $this->entityDtd);
        $xml           = $dom->createDocument('', '', $dtd);
        $xml->encoding = 'UTF-8';

        $root = $this->createRootElement($xml);
        $root->appendChild($this->createStorageElement($xml));
        $root->appendChild($this->createFieldsElement($xml));
        $root->appendChild($this->createRelationsElement($xml));

        $xml->formatOutput = true;
        $xml->save($filename);
    }