Jump to content

php xml dom


calabiyau

Recommended Posts

I'm trying to delete a node from an xml file.  The xml file is structured as follows

<pages>

<page>

<script_files>

<script>

<script_file></scriptfile>

<script_name></script_name>

</script>

</script_files>

</page>

</pages>

 

and the code i've been trying is

 

<?php
$new_page = $_POST['page'];
$script_file = $_POST['script_file'];



$xml = new DomDocument('1.0'); 
$xml->load('../database/content_db.xml'); 


$sub_doc = $xml->getElementsByTagName('page')->item($new_page);

$scripts = $sub_doc->getElementsByTagName('script_files')->item(0);

$spec_script = $scripts->getElementsByTagName('script')->item($script_file);



$olduser = $scripts->removeChild($spec_script);  

$xml->save("../database/content_db.xml"); 

?>


 

Thing is I had this sort of working with similar code but have gotten lost along the way.  Anyone familiar with this sort of work that could send me in the right direction?  Thanks

Link to comment
https://forums.phpfreaks.com/topic/136754-php-xml-dom/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.