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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.