Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing XML with PHP
    text
    copied!<p>I'm trying to parse a jobs feed using PHP's SimpleXML. I've only used JSON before and am having problems getting the parser to work. Here's some sample data:</p> <pre><code>&lt;shrs&gt; &lt;rq url="http://api.simplyhired.com/a/jobs-api/xml_v2/q-comission"&gt; &lt;t&gt;Comission Jobs&lt;/t&gt; &lt;dt&gt;2011-02-18T23:58:38Z&lt;/dt&gt; &lt;si&gt;0&lt;/si&gt; &lt;rpd&gt;10&lt;/rpd&gt; &lt;tr&gt;192&lt;/tr&gt; &lt;tv&gt;146&lt;/tv&gt; &lt;em url=""/&gt; &lt;h&gt; &lt;kw pos="1"/&gt; &lt;/h&gt; &lt;/rq&gt; &lt;rs&gt; &lt;r&gt; &lt;jt&gt;Virtual Recruiter (IT) - Comission ...&lt;/jt&gt; &lt;cn url=""&gt;Remedy Intelligent Staffing&lt;/cn&gt; &lt;src url="http://api.simplyhired.com/a/job-details/view/jobkey-monster91949932/cjp-0/hits-192?aff_id=28700"&gt;Monster&lt;/src&gt; &lt;ty&gt;organic&lt;/ty&gt; &lt;loc cty="Buffalo" st="NY" postal="14211" county="" region="" country="US"&gt;Buffalo, NY&lt;/loc&gt; &lt;ls&gt;2011-02-04T05:51:17Z&lt;/ls&gt; &lt;dp&gt;2011-02-04T05:51:17Z&lt;/dp&gt; &lt;e&gt; Seeking a candidate with previous recruiting experience to work as a Virtual Recruiter for a large client in the IT industry.a Responsibilities: Will recruit, screen, interview, and place candidates for many openings throughout the US Will... &lt;/e&gt; &lt;/r&gt; &lt;r&gt; &lt;jt&gt;Virtual Loan Officer (Mortgage) draw vs comission&lt;/jt&gt; &lt;cn url=""&gt;Netbranchology.com&lt;/cn&gt; &lt;src url="http://api.simplyhired.com/a/job-details/view/jobkey-7114.353281/cjp-2/hits-192?aff_id=28700"&gt;netbranchology.com&lt;/src&gt; &lt;ty&gt;organic&lt;/ty&gt; &lt;loc cty="Denver" st="CO" postal="80218" county="" region="" country="US"&gt;Denver, CO&lt;/loc&gt; &lt;ls&gt;2011-02-10T11:47:50Z&lt;/ls&gt; &lt;dp&gt;2011-01-26T11:36:18Z&lt;/dp&gt; &lt;e&gt; Minimize your overhead by becoming a virtual loan officer... Our client, a Texas-based mortgage banker, has just launched an innovative new program that lets you work from anywhere to originate residential mortgage loans. No office is... &lt;/e&gt; &lt;/r&gt; &lt;/rs&gt; &lt;/shrs&gt; </code></pre> <p>[etc]</p> <p>I'd like to retrieve the metadata in the tags into variables, and then loop through each job result under to process it. How can I do this with PHP? (I've been playing around with the SimpleXML functions so far)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload