Jump to content

Delete xml data


socox11

Recommended Posts

Hi all,

 

I'am new with PHP, and I need help with this one. I have this XML structure:

 

<?xml version="1.0" encoding="UTF-8"?>
<popis>
     <student>
          <prezime>Brkic</prezime>
          <ime>Ivica</ime>
          <index>D-142</index>
     </student>
     <student>
          <prezime>Cizek</prezime>
          <ime>Pero</ime>
          <index>D-143</index>
     </student>
</popis>

 

and I have this PHP code to get all elements from XML file to html table:

 

<?php
$doc = new DOMDocument();
$doc->load( 'student.xml' );
  
$popis = $doc->getElementsByTagName( "student" );

echo <<<EOF
<table>
        <tr>
                <th width=100 >IME</th>
                <th width=100>PREZIME</th>
                <th width=100>INDEX</th>
        </tr>

EOF;
foreach( $popis as $student )
{
  $imena = $student->getElementsByTagName( "ime" );
  $ime = $imena->item(0)->nodeValue;
  
  $prezimena= $student->getElementsByTagName( "prezime" );
  $prezime= $prezimena->item(0)->nodeValue;
  
  $indexi = $student->getElementsByTagName( "index" );
  $index = $indexi->item(0)->nodeValue;
echo <<<EOF
        <tr>
                <td>{$ime}</td>
                <td>{$prezime}</td>
                <td>{$index}</td>
        </tr>

EOF;
}
echo '</table>';
?>

 

Now I would like to know how to delete node from XML document? Something like, when I enter number of node I wanna delete in some iput field, or by searching, what ever, just that I can specify which node to delete...

 

My eng is not very good, hope you understand... ty

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/226953-delete-xml-data/
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.