delete info in xml doc via php

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

  • kevk3v
    replied
    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

    Leave a comment:


  • cobusbo
    replied
    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?

    Leave a comment:


  • just_m3.
    replied
    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.

    Leave a comment:


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

    Leave a comment:


  • shushant
    replied
    Code:
       print_r(
         json_decode( json_encode( simplexml_load_file('xmlfile.xml'), true));
    
    
              )

    Leave a comment:


  • cobusbo
    started a topic delete info in xml doc via php

    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.
Working...
X