private function serializePortableProperties($properties, $ns = '', $nsUri = '', $name = null, $element = null){
        $document = null;
        $result = '';

        if ($element === null) {
            $document = new \DomDocument();
            $element = $ns ?
                $document->createElementNS($nsUri, $ns . ':properties') :
                $document->createElement('properties');

            $document->appendChild($element);
        } else {
            $newElement = $ns ?
                $element->ownerDocument->createElementNS($nsUri, $ns . ':properties') :
                $element->ownerDocument->createElement('properties');

            $element->appendChild($newElement);
            $element = $newElement;
        }

        if ($name !== null) {
            $element->setAttribute('key', $name);
        }

        foreach ($properties as $name => $value) {
            if(is_array($value)){
                $this->serializePortableProperties($value, $ns, $nsUri, $name, $element);
            } else {
                $entryElement = $ns ?
                    $element->ownerDocument->createElementNS($nsUri, $ns . ':property') :
                    $element->ownerDocument->createElement('property');

                $entryElement->setAttribute('key', $name);
                $entryElement->appendChild(new \DOMText($value));
                $element->appendChild($entryElement);
            }
        }

        if ($document !== null) {
            foreach ($document->childNodes as $node) {
                $result .= $document->saveXML($node);
            }
        }

        return $result;
    }