SimpleXML parse to HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
okelly
Forum Commoner
Posts: 29
Joined: Thu Feb 23, 2006 2:18 pm

SimpleXML parse to HTML

Post by okelly »

Hello everybody

I'm trying to loop through the xml file here http://www.sec.gov/Archives/edgar/xbrlrss.xml and return the value for each edgar:cikNumber in the file .
The syntax I'm using is below and obviously wrong as it's not returning any data. Can somebody kindly point me to the correct syntax.
The error is in one of the two lines;

Code: Select all

foreach ($rss->channel->item->edgar:xbrlFiling as $filing) {
  echo "<p>" . $filing->edgar:cikNumber . "</p>";
thanks very much.
//C

Code: Select all

<?php // Load and parse the XML document 
$rss =  simplexml_load_file('http://www.sec.gov/Archives/edgar/xbrlrss.xml');
$title =  $rss->channel->title;
?>
<html xml:lang="en" lang="en">
<head>
<title><?php echo $title; ?></title>
</head>
<body>
 
 
<?php
// loop to include each item and generate a html table 
 
foreach ($rss->channel->item->edgar:xbrlFiling as $filing) {
  echo "<p>" . $filing->edgar:cikNumber . "</p>";
 
} 
         
?>
</body>
</html>
okelly
Forum Commoner
Posts: 29
Joined: Thu Feb 23, 2006 2:18 pm

Re: SimpleXML parse to HTML

Post by okelly »

I should perhaps have included that in addition to returning the value of each edgar:cikNumber I'd also like , in a different file, to return each UNIQUE value of edgar:cikNumber (ie where it is encountered more than once in the source xml file the php script should return the value only once , rather than return each incidence) .

If somebody could provide the syntax for both options I'd be obliged. thanks very much

/C
Post Reply