Edit an XML within compressed tgz file without extracting it

184 Views Asked by At

I have been trying to modify an XML document within an archived .tgz file by using the PharData class using php. I have no problem modifying the XML through DomDocument class, but I am having a hard time saving the whole process: I end up saving 2 different .phar documents alltogether, w/o modifying anything in the .tgz archive :

folder example image

Here is the code I have been using :

            $phar = new PharData($path . '/' . $idClient . '/' . $tempDate->format('ym') . '/' . $file);

            echo $phar . "\n";

            $dom = new DOMDocument();
            $dom->load ('phar://' . $path . '/' . $idClient . '/' . $tempDate->format('ym') . '/' . $file . '/' . substr($file, 0, -4) . '.xml');

            if ($dom === null) continue;
            $ids = $dom->documentElement->getElementsByTagName('id');

            foreach ($ids as $i_id) {
                if ($i_id->nodeValue !== $id) continue;
                echo $i_id->nodeValue . "\n";
                echo $i_id->nodeName . "\n";
                $sensor = $i_id->parentNode;
                echo $sensor->nodeName . "\n";
                foreach ($sensor->childNodes as $object) {
                    if ($object->nodeName !== 'type') continue;
                    echo $object->nodeName . "\n";
                    echo $object->nodeValue . "\n";
                    $object->nodeValue = $type;
                    echo $object->nodeValue . "\n" . "\n";
                }       
            }
            $dom->save('phar://' . $path . '/' . $idClient . '/' . $tempDate->format('ym') . '/' . $file . '.phar' . '/' . substr($file, 0, -4) . '.xml');
0

There are 0 best solutions below