public function insertPI($target, $data = null, $mode = 'before')
    {
        $tmp = dom_import_simplexml($this);
        $doc = $tmp->ownerDocument;

        if (isset($data)) {
            if (is_array($data)) {
                $str = '';
                foreach ($data as $k => $v) {
                    $str .= $k . '="' . htmlspecialchars($v) . '" ';
                }

                $data = substr($str, 0, -1);
            } else {
                $data = (string)$data;
            }

            $pi = $doc->createProcessingInstruction($target, $data);
        } else {
            $pi = $doc->createProcessingInstruction($target);
        }

        if ($pi !== false) {
            $this->insertNode($tmp, $pi, $mode);
        }

        return $this;
    }