Page 1 of 1

SimpleXML parse to HTML

Posted: Sat Dec 06, 2008 7:50 am
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>

Re: SimpleXML parse to HTML

Posted: Sat Dec 06, 2008 8:41 am
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