SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help in update xml data using php dom

    Hi i am having difficulties to update the cmark data.in other words, i dont have any idea on how to do it.

    studentsubject.xml

    Code:
    <?xml version="1.0"?>
    <students>
    <student sid="amuk">
    <id>20088</id>
    <subject>PHP</subject>
    <code>CSC572</code>
    <cmark>10</cmark>
    <lectid>mus</lectid>
    </student>
    <students>
    <student sid="lan">
    <id>200828</id>
    <subject>XHTML</subject>
    <code>CSC576</code>
    <cmark>30</cmark>
    <lectid>mus</lectid>
    </student>
    <students>
    <student sid="musa">
    <id>2008288868</id>
    <subject>XML</subject>
    <code>CSC570</code>
    <cmark>30</cmark>
    <lectid>mus</lectid>
    </student>

    php code

    PHP Code:

    <?php

    if(isset($_POST['Submit']))
    {

    //help i dont have any idea

    ?>

  2. #2
    SitePoint Zealot evilunix's Avatar
    Join Date
    Jun 2008
    Location
    York, UK.
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse the current XML with the simplexml_load_file() function. Build up the new XML file using basic string concatenation, then save the file!

    Not used the PHP DOM before, it can't take much longer to do it like this, it's easy to build an XML file manually

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi care to elaborate more?my level in using xml in php is this is 2nd day i use it

  4. #4
    SitePoint Zealot evilunix's Avatar
    Join Date
    Jun 2008
    Location
    York, UK.
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check out this tut http://devzone.zend.com/node/view/id/651

    I can't find the one that helped me learn, but this one is pretty similar. I will post some code tomorrow if you are still stuck!

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man!

    Hi i think i need your help in xpath.And plz correct me

    The logic is when the lecturer enter the cmark and submit, the cmark of the specified student identify using sid and code will be updated.


    <?php

    $cmark = $_POST['cmark'];
    $sid = "musa";
    $code = "CSC570";

    $file = "users/studentsubject.xml";

    // load file
    $xml = simplexml_load_file($file) or die ("Unable to load XML file!");

    // how to select data with student sid = musa and code = CSC570 using xpath?

    foreach ($xml->xpath('//item[quantity > 1]/desc') as $desc) {
    echo "$desc\n";

    $desc->cmark = $cmark;

    file_put_contents($file, $xml->asXML());

    }

    ?>

  6. #6
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code works great, except, it appears to add a full node inside of existing tags instead of just updating the node. Any idea why?

    Mapper


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •