SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: XML and PHP 5

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Sydney
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML and PHP 5

    Is anyone here using it?

    I've got the latest snapshot and trying the examples in the CVS dir, but getting some errors.

    Code:
    <?xml version="1.0"?>
    <sec>
    	<security>
    		<id>22</id>
    		<touch>you</touch>
    	</security>
    	<security>
    		<id>21</id>
    		<touch>me</touch>
    	</security>
    	<security>
    		<id>20</id>
    		<touch>me</touch>
    	</security>
    </sec>
    PHP Code:
    $s simplexml_load_file('security.xml');
    echo 
    $s->security->id// Works
    echo $s->security[1]->id// Works
    echo $s->security[2]->id// Doesn't work 

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works fine in PHP Version 5.0.0b3

    PHP Code:
    <?php
      $s 
    simplexml_load_file('security.xml'); 
      echo 
    '0 = '.$s->security[0]->id .'<br />'// Works - However "$s->security]->id" Does not
      
    echo '1 = '.$s->security[1]->id .'<br />'// Works
      
    echo '2 = '.$s->security[2]->id .'<br />'// Works
    ?>
    Output
    0 = 22
    1 = 21
    2 = 20

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Sydney
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope I only get
    0 = 22
    1 = 21
    2 = 21

    :| I posted a bug report, but yeh wierd.

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2003
    Location
    Virginia
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mabey because the first line doesn;t use an array.

    echo $s->security->id; // Works


    insted of

    echo $s->security[0]->id; // Works


  5. #5
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Sydney
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Resolution, yeh in PHP beta 3 that will fail, in CVS it works. But in CVS it fails on $s->security[2]->id, but in Beta 3 it works. So I reverted back to Beta 3, but now it doesnt support $s->asXML(file.xml); So I cant save it. :|

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2003
    Location
    Virginia
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In PHP 5, can you convert the simpleXML object into DOM or save to file using the libXML extention?

    Res

  7. #7
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Sydney
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use simpleXML(libxml extensions) to save XML files. But there is also DOM stuff.


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
  •