Parsing XML with PHP -
i'm trying parse jobs feed using php's simplexml. i've used json before , having problems getting parser work. here's sample data:
<shrs> <rq url="http://api.simplyhired.com/a/jobs-api/xml_v2/q-comission"> <t>comission jobs</t> <dt>2011-02-18t23:58:38z</dt> <si>0</si> <rpd>10</rpd> <tr>192</tr> <tv>146</tv> <em url=""/> <h> <kw pos="1"/> </h> </rq> <rs> <r> <jt>virtual recruiter (it) - comission ...</jt> <cn url="">remedy intelligent staffing</cn> <src url="http://api.simplyhired.com/a/job-details/view/jobkey-monster91949932/cjp-0/hits-192?aff_id=28700">monster</src> <ty>organic</ty> <loc cty="buffalo" st="ny" postal="14211" county="" region="" country="us">buffalo, ny</loc> <ls>2011-02-04t05:51:17z</ls> <dp>2011-02-04t05:51:17z</dp> <e> seeking candidate previous recruiting experience work virtual recruiter large client in industry.a responsibilities: recruit, screen, interview, , place candidates many openings throughout will... </e> </r> <r> <jt>virtual loan officer (mortgage) draw vs comission</jt> <cn url="">netbranchology.com</cn> <src url="http://api.simplyhired.com/a/job-details/view/jobkey-7114.353281/cjp-2/hits-192?aff_id=28700">netbranchology.com</src> <ty>organic</ty> <loc cty="denver" st="co" postal="80218" county="" region="" country="us">denver, co</loc> <ls>2011-02-10t11:47:50z</ls> <dp>2011-01-26t11:36:18z</dp> <e> minimize overhead becoming virtual loan officer... our client, texas-based mortgage banker, has launched innovative new program lets work anywhere originate residential mortgage loans. no office is... </e> </r> </rs> </shrs>
[etc]
i'd retrieve metadata in tags variables, , loop through each job result under process it. how can php? (i've been playing around simplexml functions far)
nodes accessed object properties, attributes use array notation. foreach
lets iterate on nodes. can content of node casting string. (so if use echo
it's implied)
$shrs = simplexml_load_string($xml); foreach ($shrs->rs->r $r) { $jobtitle = $r->jt; $city = $r->loc['cty']; echo "there's offer $jobtitle in $city<br />\n"; }
Comments
Post a Comment