Home > Articles > XML crud operations using php

XML crud operations using php

Hi friends,In this post i would like to explain about curd operations ( add, edit and delete ) data using xml file. It is simple to maintain and rapid in the operations, it will be useful when simple operations required.
Below code explain the how to insert , edit , view and delete operations using database and xml format.

xml crud operations using php | Anil Labs

xml crud operations using php | Anil Labs

Connection establish :

Mysql :

   $con = mysql_connect('Server Host Name','User Name' ,'Password');
   mysql_select_db('Database name',$con);


   $xml = simplexml_load_file("users.xml"); //This line will load the XML file.
   $sxe = new SimpleXMLElement($xml->asXML());

View the details:


    <?php $query   = "SELECT * FROM users";
          $result  = mysql_query($query);
          while($resUsers = mysql_fetch_assoc($result)){
            echo $resUsers['name']
          } ?>


     $rows = count($sxe);
       echo  ($sxe->users[$i]->name);

Insert the details:


    $query = "insert into users(id,name)values($id,'$name')";
    $result = mysql_query($quesry);


    $no_rows = count($sxe);
    $query = $sxe->addChild("users");  
    $query->addChild("id", $no_rows+1);
    $query->addChild("name",  ($name));

Edit the details:

Mysql :

    $query = "select * from users where id=".$edit_id;
    //and update query :
    $query_update = "update users set name = '$name' where id=$edit_id";
    $result = mysql_query($query_update);


    <?php $rows = count($sxe);
    for($i = 0, $length = $rows; $i < $length; $i++){
       if($sxe->users[$i]->id == $edit_id){ ?>
       <input value="<?php echo $sxe->users[$i]->name;?>">
       <? }


    $rows = count($sxe);
    for($i = 0, $length = $rows; $i < $length; $i++){
         if($sxe->users[$i]->id == $edit_id){
            $sxe->users[$i]->name =  ($name);

Delete the details:

Mysql :

    $query = "delete from users where id=".$edit_id;
    $result = mysql_query($query);


    $rows = count($sxe);
    for($i = 0, $length = $rows; $i < $length; $i++){
        if($sxe->users[$i]->id == $edit_id){


CREATE TABLE `users` (
`name` VARCHAR( 250 ) NOT NULL

XML File:


<?xml version="1.0" encoding="iso-8859-1"?>
You may also like
Website uptime monitoring using PHP script
Understanding the basic need of MVC architecture
How to convert feeds to html using javascript and php
Multi-language support for web application with MySql and PHP

5 Responses

  1. Pingback : Tweets that mention xml crud operations using php « ANIL KUMAR PANIGRAHI 's Blog -- Topsy.com

  2. ritesh

    I have problem in my xml size 600 mb or large same type of 20 other files
    i want to insert into mysql table
    xml format like

    147OmahaSteaks.com, Inc.2013-02-15/11:08:17Food & DrinkSeafood Appetizershttp://click.linksynergy.com/link?id=q6gkJqWDpGA&offerid=7537.2182&type=15&murl=http%3A%2F%2Fwww.omahasteaks.com%2Fservlet%2Foh%3FDSP%3D14%26AID%3D1%26SRC%3DAE6055%26ITMSUF%3DHHW%26IID%3D2182%26partnerid%3Dcpcs.linksharehttp://www.omahasteaks.com/gifs/big/sf098.jpghttp://click.linksynergy.com/link?id=q6gkJqWDpGA&offerid=7537.2182&type=15&murl=http%3A%2F%2Fwww.omahasteaks.com%2Fservlet%2Foh%3FDSP%3D14%26AID%3D1%26SRC%3DAE2886%26ITMSUF%3DNSF%26IID%3D21821 (1.5 lb. pkg.) Oven Fried ShrimpA traditional favorite at seafood restaurants, our Oven Fried Shrimp is sure to become a family favorite, too! We start with tender, meaty jumbo shrimp then we dip them in a golden crispy batter. All you do is bake and serve! It doesn’t get much easier than that. Pair them with our Sweet and Tangy Cocktail sauce for the perfect appetizer, or serve with fries and coleslaw for a delicious meal.8.00amount17.9925.99Omaha Steaks13.99UPS, GROUNDshrimp appetizer, fried shrimp, jumbo shrimp, tempura shrimp, baked shrimp, seafood, seafood appetizer, appetizers, easy appetizers, party appetizershttp://ad.linksynergy.com/fs-bin/show?id=q6gkJqWDpGA&bids=7537.2182&type=15&subid=0
    Food & Drink4 – 8 Steak Combinationshttp://click.linksynergy.com/link?id=q6gkJqWDpGA&offerid=7537.501&type=15&murl=http%3A%2F%2Fwww.omahasteaks.com%2Fservlet%2Foh%3FDSP%3D14%26AID%3D1%26SRC%3DAE6055%26ITMSUF%3DHHW%26IID%3D501%26partnerid%3Dcpcs.linksharehttp://www.omahasteaks.com/gifs/big/cmb501.jpghttp://click.linksynergy.com/link?id=q6gkJqWDpGA&offerid=7537.501&type=15&murl=http%3A%2F%2Fwww.omahasteaks.com%2Fservlet%2Foh%3FDSP%3D14%26AID%3D1%26SRC%3DAE2886%26ITMSUF%3DNSF%26IID%3D501The EmperorOur most tender steak, the Filet Mignon, together with our most robust steak, the Top Sirloin … it’s a combination fit for royalty! You’ll love our tender, mild Filet Mignons … for a truly elegant steak experience. Looking for bold, beefy flavor? Look no further than our lean, flavorful Top Sirloins.85.01amount89.99175.00Omaha Steaks19.99UPS, GROUNDSteak combos, steak assortments, steak variety packshttp://ad.linksynergy.com/fs-bin/show?id=q6gkJqWDpGA&bids=7537.501&type=15&subid=0
    Food & Drink24 oz. Porterhouse Steakshttp://click.linksynergy.com/link?id=q6gkJqWDpGA&offerid=7537.1640&type=15&murl=http%3A%2F%2Fwww.omahasteaks.com%2Fservlet%2Foh%3FDSP%3D14%26AID%3D1%26SRC%3DAE6055%26ITMSUF%3DHHW%26IID%3D1640%26partnerid%3Dcpcs.linksharehttp://www.omahasteaks.com/gifs/big/tb011.jpghttp://click.linksynergy.com/link?id=q6gkJqWDpGA&offerid=7537.1640&type=15&murl=http%3A%2F%2Fwww.omahasteaks.com%2Fservlet%2Foh%3FDSP%3D14%26AID%3D1%26SRC%3DAE2886%26ITMSUF%3DNSF%26IID%3D16402 (24 oz.) Porterhouse SteaksNothing satisfies a really big steak appetite like an Omaha Steaks Porterhouse! It’s like having a whole Filet Mignon and a whole Strip Sirloin on your plate…all with the flavor-enhancing bone left in!50.01amount79.99130.00Omaha Steaks16.99UPS, GROUNDPorterhouse Steak, beef tenderloin, strip steak, tbonehttp://ad.linksynergy.com/fs-bin/show?id=q6gkJqWDpGA&bids=7537.1640&type=15&subid=0
    Food & DrinkVegetableshttp://click.linksynergy.com/link?id=q6gkJqWDpGA&offerid=7537.1518&type=15&murl=http%3A%2F%2Fwww.omahasteaks.com%2Fservlet%2Foh%3FDSP%3D14%26AID%3D1%26SRC%3DAE6055%26ITMSUF%3DHHW%26IID%3D1518%26partnerid%3Dcpcs.linksharehttp://www.omahasteaks.com/gifs/big/sp041.jpghttp://click.linksynergy.com/link?id=q6gkJqWDpGA&offerid=7537.1518&type=15&murl=http%3A%2F%2Fwww.omahasteaks.com%2Fservlet%2Foh%3FDSP%3D14%26AID%3D1%26SRC%3DAE2886%26ITMSUF%3DNSF%26IID%3D15182 (7 oz. trays) Roasted Vegetable MedleyA medley of fire roasted vegetables including carrots, cauliflower, sugar snap peas and pepper strips in a seasoned butter sauce are the perfect complement to any meal!11.00amount9.9920.99Omaha Steaks13.99UPS, GROUNDSide dishes, stuffed baked potatoes, vegetables, risotto cakes, Spanish rice, gourmet recipeshttp://ad.linksynergy.com/fs-bin/show?id=q6gkJqWDpGA&bids=7537.1518&type=15&subid=0

    one xml min 200000 or 500000 record please guide me

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.