Can't get this small piece of code to work? Need help

Discussion in 'XML' started by SM, Jun 3, 2008.

  1. SM

    SM Guest

    Can't get this small piece of code to work? Need help

    I have a XML that looks like this:
    <?xml version="1.0" encoding="utf-8"?>
    <VIDEO>
    <item>
    <title>Letters</title>
    <videos>
    <title>a</title>
    <title>b</title>
    <title>c</title>
    </videos>
    </item>

    <item>
    <title>Numbers</title>
    <videos>
    <title>1</title>
    <title>2</title>
    <title>3</title>
    </videos>
    </item>
    </VIDEO>



    $file = 'db.xml';
    $xml = @simplexml_load_file($file);

    foreach($xml->item as $item) {
    echo 'Letters ' . $item->title;

    foreach($item->videos as $vid) {
    echo $vid->title;
    }
    }


    Output: LettersaNumbers1
    It should be: LettersabcNumbers123

    What's wrong?

    Thanks
    Marco
     
    SM, Jun 3, 2008
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Moritz Beller
    Replies:
    19
    Views:
    883
    Pete Becker
    Jun 4, 2004
  2. jblazi
    Replies:
    5
    Views:
    603
    jblazi
    Aug 16, 2004
  3. Replies:
    6
    Views:
    550
    Keith Thompson
    May 17, 2006
  4. Xeno Campanoli
    Replies:
    1
    Views:
    490
    James Britt
    Jul 1, 2005
  5. Patrick Plattes

    Download a file piece by piece

    Patrick Plattes, Nov 30, 2006, in forum: Ruby
    Replies:
    2
    Views:
    385
    Patrick Plattes
    Nov 30, 2006
  6. Gaba Luschi

    question about a small piece of code

    Gaba Luschi, Feb 20, 2011, in forum: Ruby
    Replies:
    2
    Views:
    179
    masdel
    Feb 20, 2011
  7. Replies:
    1
    Views:
    172
    Mumia W. (reading news)
    Nov 2, 2006
  8. SM
    Replies:
    2
    Views:
    340
Loading...