Posts

Showing posts from 2011

How to modify xml data using php - Part 2

Use the following code to update the submitted value from modify.php into xml: <?php function  update_book_id ( $id ,   $filename   =   'loaned.xml' ) { $data   =  simplexml_load_file ( $filename ); for ( $i   =   0 ,   $length   =  count ( $data -> resource -> book );   $i   <   $length ;   $i ++)      {      if ( $data -> resource -> book [ $i ]-> ID  ==   $id )          {                  $btitle   =   $_POST [ 'btitle' ];                   $bdate   =   $_POST [ 'bdate' ];          $bookrentdate   =   $_POST [ 'bookrentdate' ];          $...

How to modify xml data using php - Part 1

In modify.php add the following code: <?php $modifybook = $_GET [ 'bid' ]; $doc = new DOMDocument (); $doc -> load ( 'loaned.xml' );   $booklist = $doc -> getElementsByTagName ( "book" ); foreach ( $booklist as $book ) { $bookids = $book -> getElementsByTagName ( "ID" ); $bookid = $bookids -> item ( 0 )-> nodeValue ; if ( $bookid == $modifybook ){       $booktitles = $book -> getElementsByTagName ( "title" );       $booktitle = $booktitles -> item ( 0 )-> nodeValue ;       $dates = $book -> getElementsByTagName ( "date" );       $date = $dates -> item ( 0 )-> nodeValue ;             $retdates = $book -> getElementsByTagName ( "retdate" );       $retdate = $retdates -> item ( 0 )-> nodeValue ;       ...

How to delete xml node using php

Create delete.php file and add the following code <?php function delete_book_id ( $id , $filename = 'loaned.xml' ) { $data = simplexml_load_file ( $filename ); for ( $i = 0 , $length = count ( $data -> resource -> book ); $i < $length ; $i ++)     {     if ( $data -> resource -> book [ $i ]-> ID == $id )         {         unset ( $data -> resource -> book [ $i ]);         break ;         }     }     file_put_contents ( $filename , $data -> saveXML ());     echo $deletingbook . " Deleted !!!" ; } //SAMPLE USAGE $deletingbook = $_GET [ 'bid' ]; delete_book_id ( $deletingbook );  header ( "Location: {$_SERVER['HTTP_REFERER']} " ); //delete_book_id('Book 1'); ?>

How to add new content in XML using php

In index.php add the following form for inserting new data in xml using php <form action = "booklistaction.php" method = "post" >   <table>    <tr>        <td colspan = "2" class = "labelcell" ><label for = "btitle" > Book Title: </label></td>      <td colspan = "2" class = "fieldcell" ><input type = "text" id = "btitle" name = "btitle"   tabindex = "1" /></td>    </tr>       <tr>        <td colspan = "2" class = "labelcell" ><label for = "bdate" > Book Issue date: </label></td>      <td colspan = "2" class = "fieldcell" > <input type = "text" id = "bdate" name = "bdate"   tabindex = "2" /><br /> </td>    </tr>          <tr>    ...