src/XQueue/Maileon/API/Contacts/Contact.php
function toXML($addXMLDeclaration = true)
    {
        $xmlString = $addXMLDeclaration ? "<?xml version=\"1.0\"?><contact></contact>" : "<contact></contact>";
        $xml = new SimpleXMLElement($xmlString);

        // Some fields are mandatory, especially when setting data to the API
        if (isset($this->id)) $xml->addChild("id", $this->id);

        // As shown in http://stackoverflow.com/questions/17027043/unterminated-entity-reference-php a & char causes trouble with addChild.
        // Use this workaround
        if (isset($this->email)) {
            $emailChild = $xml->addChild("email");
            $xml->email = $this->email;
        }

        if (isset($this->permission)) $xml->addChild("permission", $this->permission->getCode());
        if (isset($this->external_id) && $this->external_id != -1) $xml->addChild("external_id", $this->external_id);
        if (isset($this->anonymous)) $xml->addChild("anonymous", $this->anonymous);

        if (isset($this->created)) $xml->addChild("created", $this->created);
        if (isset($this->updated)) $xml->addChild("updated", $this->updated);

        if (isset($this->standard_fields)) {
            $standard_fields = $xml->addChild("standard_fields");
            foreach ($this->standard_fields as $index => $value) {
                $field = $standard_fields->addChild("field");
                $field->addChild("name", $index);

                XMLUtils::addChildAsCDATA($field, "value", $value);
                //$field->addChild("value", $value);
            }
        }

        if (isset($this->custom_fields)) {
            $customfields = $xml->addChild("custom_fields");
            foreach ($this->custom_fields as $index => $value) {
                $field = $customfields->addChild("field");
                $field->addChild("name", $index);

                XMLUtils::addChildAsCDATA($field, "value", $value);
                //$field->addChild("value", $value);
            }
        }

        return $xml;
    }
function toXML($addXMLDeclaration = true)
    {
        $xmlString = $addXMLDeclaration ? "<?xml version=\"1.0\"?><contact></contact>" : "<contact></contact>";
        $xml = new SimpleXMLElement($xmlString);

        // Some fields are mandatory, especially when setting data to the API
        if (isset($this->id)) $xml->addChild("id", $this->id);

        // As shown in http://stackoverflow.com/questions/17027043/unterminated-entity-reference-php a & char causes trouble with addChild.
        // Use this workaround
        if (isset($this->email)) {
            $emailChild = $xml->addChild("email");
            $xml->email = $this->email;
        }

        if (isset($this->permission)) $xml->addChild("permission", $this->permission->getCode());
        if (isset($this->external_id) && $this->external_id != -1) $xml->addChild("external_id", $this->external_id);
        if (isset($this->anonymous)) $xml->addChild("anonymous", $this->anonymous);

        if (isset($this->created)) $xml->addChild("created", $this->created);
        if (isset($this->updated)) $xml->addChild("updated", $this->updated);

        if (isset($this->standard_fields)) {
            $standard_fields = $xml->addChild("standard_fields");
            foreach ($this->standard_fields as $index => $value) {
                $field = $standard_fields->addChild("field");
                $field->addChild("name", $index);

                XMLUtils::addChildAsCDATA($field, "value", $value);
                //$field->addChild("value", $value);
            }
        }

        if (isset($this->custom_fields)) {
            $customfields = $xml->addChild("custom_fields");
            foreach ($this->custom_fields as $index => $value) {
                $field = $customfields->addChild("field");
                $field->addChild("name", $index);

                XMLUtils::addChildAsCDATA($field, "value", $value);
                //$field->addChild("value", $value);
            }
        }

        return $xml;
    }
Serialization to a simple XML element.

@param bool $addXMLDeclaration

@return \em SimpleXMLElement
Generate a XML element from the contact object.