Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-29-2012, 07:58 PM   PM User | #1
Cyantyst
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Cyantyst is an unknown quantity at this point
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>
Cyantyst is offline   Reply With Quote
Old 10-30-2012, 12:36 AM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,365
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
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 />';
}
?>
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:51 PM.


Advertisement
Log in to turn off these ads.