public function addElement($name, $params, $parent)
    {
        $name = preg_replace("/_[0-9]+$/", "", $name);

        $element = $this->dom->createElement($name);

        if (!is_array($params)) {
            $this->setElementValue($element, $params);
        } else {
            foreach ($params as $key => $val) {
                if ($key == "_attributes") {
                    foreach ($val as $k => $v) {
                        $element->setAttribute($k, $v);
                    }
                } elseif ($key == "_value") {
                    $this->setElementValue($element, $val);
                } else {
                    $this->addElement($key, $val, $element);
                }
            }
        }

        $parent->appendChild($element);

        return $element;
    }