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
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do i display this xml file within a html page?

    <?xml version="1.0" encoding="utf-8"?>

    <people>
    <person name="Fatboy Slim" bgcolor="78A615" photo="dj1.jpg">
    <desc>12345</desc>
    <links><![CDATA[description here. Check out this link for more www.fatboyslim.com]]></links>
    </person>

    <person name="Deadmau5" bgcolor="000000" photo="dj2.jpg">
    <desc>12345</desc>
    <links><![CDATA[www.deadmau5.com]]></links>
    </person>

    <person name="Skrillex" bgcolor="374B9F" photo="dj3.jpg">
    <desc>12345</desc>
    <links><![CDATA[www.skrillex.com]]></links>
    </person>

    </people>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,486
    Thanks
    23
    Thanked 636 Times in 635 Posts
    Code:
    <?php
    $xml = simplexml_load_file("People.xml");  // I made your code into a file named People.xml
    
    $i = 0;
    foreach ($xml as $person[])
    {
    	echo $person[$i]->attributes()->name . "<br />";
    	echo $person[$i]->attributes()->bgcolor . "<br />";
    	echo $person[$i]->attributes()->photo . "<br />";
    	echo $person[$i]->desc . "<br />";
    	echo $person[$i]->links . "<br />";
    	$i++;
    	echo '===================================<br />';
    }
    ?>


  •  

    Posting Permissions

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