delete info in xml doc via php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    delete info in xml doc via php

    Hi guys I need some help I have a xml document with the following info
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <users>
     <user><name>Skuilnaam</name><score>8</score></user><user><name>Skuilnaam1</name><score>10</score></user><user><name>cobus</name><score>5</score></user></users>
    and a php script to dump rows in a table with coding to remove the info in the xml document but I cant seem to get it to work it just shows me the rows but dont delete them

    Code:
    <? 
     $db_host = "xxxxxxxxxxx";
     $db_user = "xxxxxxxxxxxx";
     $db_pass = "xxxxxxxxxxxxxx";
     $db_name = "xxxxxxxxxxx";
     $connect = @mysql_connect($db_host,$db_user,$db_pass);
     @mysql_select_db($db_name);
    static $leaderboardfile = 'res/leaders.xml';
     // Empty table
     $query = "TRUNCATE TABLE rente";
     mysql_query($query);
     ?>
    <?php
    
    $retriever = new DOMDocument();
    
    $retriever ->load( 'res/leaders.xml' );
    
    $masterElement = $retriever->documentElement;
    
    $masterContent = $masterElement->getElementsByTagName('user')->item(0);
    
    $oldContent = $masterElement->removeChild($masterContent );
    
    echo $retriever->saveXML();
    
    ?>
    can someone help me to get my php document correct so it can clean my xml document to just show the xml doc with the following info in it afterwards

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <users>
     <</users>
    Added after 21 minutes:

    Originally posted by cobusbo View Post
    Hi guys I need some help I have a xml document with the following info
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <users>
     <user><name>Skuilnaam</name><score>8</score></user><user><name>Skuilnaam1</name><score>10</score></user><user><name>cobus</name><score>5</score></user></users>
    and a php script to dump rows in a table with coding to remove the info in the xml document but I cant seem to get it to work it just shows me the rows but dont delete them

    Code:
    <? 
     $db_host = "xxxxxxxxxxx";
     $db_user = "xxxxxxxxxxxx";
     $db_pass = "xxxxxxxxxxxxxx";
     $db_name = "xxxxxxxxxxx";
     $connect = @mysql_connect($db_host,$db_user,$db_pass);
     @mysql_select_db($db_name);
    static $leaderboardfile = 'res/leaders.xml';
     // Empty table
     $query = "TRUNCATE TABLE rente";
     mysql_query($query);
     ?>
    <?php
    
    $retriever = new DOMDocument();
    
    $retriever ->load( 'res/leaders.xml' );
    
    $masterElement = $retriever->documentElement;
    
    $masterContent = $masterElement->getElementsByTagName('user')->item(0);
    
    $oldContent = $masterElement->removeChild($masterContent );
    
    echo $retriever->saveXML();
    
    ?>
    can someone help me to get my php document correct so it can clean my xml document to just show the xml doc with the following info in it afterwards

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <users>
     <</users>
    ok I manage to get it to work but now I got some other help needed

    Code:
    <?php
    
    $retriever = new DOMDocument();
    
    $retriever ->load( 'res/leaders.xml' );
    
    $masterElement = $retriever->documentElement;
    
    $masterContent = $masterElement->getElementsByTagName('user')->item(0);
    
    $oldContent = $masterElement->removeChild($masterContent );
    
    echo $retriever->saveXML();
    echo $retriever->save( 'res/leaders.xml' );
    ?>

    This delete each record as I refresh it each time, isnt there a way to delete all at once or create a table where I can tick off to delete each record? and after I deleted all the records isn't there a way to tell me there are no more records and link me back to the index? in place of getting the error



    Catchable fatal error: Argument 1 passed to DOMNode::removeChild() must be an instance of DOMNode, null given in /srv/disk1/1296487/www/rekvasvra.uni.me/Gr10/Rente/cron.php on line 23 when all records are deleted
    Last edited by cobusbo; 02.03.13, 11:22.

    #2
    Code:
       print_r(
         json_decode( json_encode( simplexml_load_file('xmlfile.xml'), true));
    
    
              )

    Comment


      #3
      Originally posted by shushant View Post
      Code:
         print_r(
           json_decode( json_encode( simplexml_load_file('xmlfile.xml'), true));
      
      
                )
      what does this do?

      Comment


        #4
        Originally posted by cobusbo View Post
        what does this do?

        it transforms your xml into array and you can acces values by name

        ex:

        Click image for larger version

Name:	hJloV7K.png
Views:	1
Size:	4.7 KB
ID:	110710
        Last edited by just_m3.; 03.03.13, 01:18.
        This is ten percent luck, twenty percent skill
        Fifteen percent concentrated power of will
        Five percent pleasure, fifty percent pain

        And a hundred percent reason to remember the name!

        Comment


          #5
          Originally posted by just_m3. View Post
          it transforms your xml into array and you can acces values by name

          ex:

          [ATTACH=CONFIG]5420[/ATTACH]
          ok so where should I include it into my code witch line?

          Comment


            #6
            Don't know what this is lol but try
            PHP Code:

            $newdata = '<?xml version="1.0" encoding="UTF-8"?>
            <users>
            </users>';

            $xmldoc = 'XML DOCUMENT NAME...';

            chmod($xmldoc,0777)
            file_put_contents($xmldoc,$newdata);
            Add after mysql_query($query); in a new line
            Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

            Comment

            Working...
            X