public function set($path, $value)
    {
        $entries = explode('/', $path);
        $lastEntry = array_pop($entries);
        reset($entries);

        // navigate to the right place in the xml - create entries ad hoc as needed
        $xml = $this->root;
        foreach ($entries as $pathEntry) {
            $xml = $this->getOrCreateNextElement($xml, $pathEntry);
        }

        list($elementName, $elementIndex) = $this->parsePathEntry($lastEntry);

        if ($elementIndex === '') {
            $xml->addChild($elementName, $value);

            return $this;
        }

        if ($elementIndex === null) {
            $xml->$elementName = $value;

            return $this;
        }

        if ($elementName === '') {
            $xml[$elementIndex] = $value;

            return $this;
        }

        // Old versions of php did not allow adding attributes to
        // non-existing elements by implicitly creating it.
        // We have to explicitly create the element.
        if (is_string($elementIndex) && empty($xml->$elementName)) {
            $el = $xml->addChild($elementName);
        } else {
            $el = $xml->$elementName;
        }

        $el[$elementIndex] = $value;

        return $this;
    }