Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    how get attribute value from xml

    hi
    i have this xml code:

    assignment name="hw1">
    <course name="CSE 154"/>
    <due>
    <date>Wed Apr 8</date>
    <time>11:30pm</time>
    </due>

    <submissions>
    <submission studentid="91" lateness="3">
    <date lateness="3">Sat Apr 11</date>
    <time>11:20pm</time>
    </submission>
    <submission studentid="26">
    <date lateness="0">Mon Apr 6</date>
    <time>9:44pm</time>
    </submission>
    <submission studentid="193">
    <date lateness="0">Sun Apr 5</date>
    <time>10:29pm</time>
    </submission>

    how can i get the value of lateness attribute??
    i try this but i can't get any results..

    <?php
    $doc = new DOMDocument();
    $doc->load( 'hw.xml' );

    $submissions = $doc->getElementsByTagName( "submission" );

    foreach( $submissions as $submission )
    {


    $lateness =$submission->$date.getAttribute('lateness');



    $times= $submission->getElementsByTagName( "time" );
    $time= $times->item(0)->nodeValue;


    echo "<b> $lateness - $time\n</b><br>";
    }
    ?>

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,460
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Double-posted and CLOSED:
    how get attribute value from xml

    You probably hit submit twice.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog


  •  

    Posting Permissions

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