Jump to content
manhattes

parsing XML

Recommended Posts

I am trying to read an RSS feed and the way my code is written, it is only repeating the first result.

 

the xml looks like this:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Latest Filings - Thu, 18 Feb 2016 14:52:36 EST</title>
<link rel="alternate" href="/cgi-bin/browse-edgar?action=getcurrent"/>
<link rel="self" href="/cgi-bin/browse-edgar?action=getcurrent"/>
<id>http://www.sec.gov/cgi-bin/browse-edgar?action=getcurrent</id>
<author><name>Webmaster</name><email>webmaster@sec.gov</email></author>
<updated>2016-02-18T14:52:36-05:00</updated>
<entry>
<title>4 - YABUKI JEFFERY W (0001207371) (Reporting)</title>
<link rel="alternate" type="text/html" href="http://www.sec.gov/Archives/edgar/data/1207371/000120919116099734/0001209191-16-099734-index.htm"/>
<summary type="html">
 <b>Filed:</b> 2016-02-18 <b>AccNo:</b> 0001209191-16-099734 <b>Size:</b> 13 KB
</summary>
<updated>2016-02-18T14:51:18-05:00</updated>
<category scheme="http://www.sec.gov/" label="form type" term="4"/>
<id>urn:tag:sec.gov,2008:accession-number=0001209191-16-099734</id>
</entry>
<entry>
<title>4 - FISERV INC (0000798354) (Issuer)</title>
<link rel="alternate" type="text/html" href="http://www.sec.gov/Archives/edgar/data/798354/000120919116099734/0001209191-16-099734-index.htm"/>
<summary type="html">
 <b>Filed:</b> 2016-02-18 <b>AccNo:</b> 0001209191-16-099734 <b>Size:</b> 13 KB
</summary>
<updated>2016-02-18T14:51:18-05:00</updated>
<category scheme="http://www.sec.gov/" label="form type" term="4"/>
<id>urn:tag:sec.gov,2008:accession-number=0001209191-16-099734</id>

and my code is like this:

$context  = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = 'http://www.sec.gov/cgi-bin/browse-edgar?action=getcurrent&CIK=&type=4&company=&dateb=&owner=include&start=100&count=20&output=atom';
$xml = file_get_contents($url, false,$context);
$xml = simplexml_load_string($xml);

print_r($xml);


foreach ($xml->entry as $entry){
        $FnumI=$xml->entry->title;
		//$FnumC=$xml->entry->title;
        $Fdate=$xml->entry->updated;
        $Flink=$xml->entry->link->attributes()->href;
		$Form=$xml->entry->category->attributes()->term;
		
       echo "<tr>";
    
    echo "<td><p>".$FnumI."</p></td>";
	//echo "<td><p>".$FnumC."</p></td>";
	echo "<td><p>".$Fdate."</p></td>";
	echo "<td><p><a href='".$Flink."'> ". $Flink."</p></td>";
	echo "<td><p>".$Form."</p></td>";
	echo "</tr>";
	        }

Share this post


Link to post
Share on other sites

Inside the foreach loop you have to use $entry. $xml->entry-> will only get you stuff from the first .

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.