You are here:  » Match the name=""


Match the name=""

Submitted by mrtshaw on Mon, 2010-03-08 12:14 in

Hi there, how do I go about getting the data from the classification name="" instead of the order they are in?

I am currently using the code MagicParser_parse($file,"myRecordHandler","xml|JOBS/JOB/"); but when pulling the data it currently says

$record["CLASSIFICATIONS/CLASSIFICATION"]
$record["CLASSIFICATIONS/CLASSIFICATION@1"]

But some jobs may not contain the classifications in that particular order or have all the fields names.

<Job>
  <Job jid="508192" reference="140534 (free)" datePosted="2010-03-06">
    <Title>Specialty Store Manager- Chadstone</Title>
    <Summary>Are you an experienced and intelligent retailer with a highly successful work history? This could be the career defining role you have always wanted!</Summary>
    <Description><![CDATA[JOB DETAILS]]></Description>
    <SearchTitle>Specialty Store Manager- Chadstone</SearchTitle>
    <BulletPoints>
      <BulletPoint>Market leading specialty retailer!</BulletPoint>
      <BulletPoint>An exceptional salary package on offer to attract the very best!</BulletPoint>
      <BulletPoint>Outstanding career opportunities for a high performing retail operator!</BulletPoint>
    </BulletPoints>
    <Classifications>
      <Classification jid="10005" name="Category">Store Operations</Classification>
      <Classification jid="10006" name="Sub Category">Store Manager</Classification>
      <Classification jid="10007" name="Work Type">Full Time</Classification>
      <Classification jid="10008" name="Location">Melbourne</Classification>
    </Classifications>
    <Fields />
    <Apply>
      <EmailTo>EMAIL</EmailTo>
      <Url>URL</Url>
    </Apply>
  </Job>
</Jobs>

Submitted by support on Mon, 2010-03-08 12:24

Hi,

What I would suggest is reading the classifications into their own associative array, and then you can read from that array by name directly so that you don't have to rely on knowing the position.

Have a go with something like this; within your myRecordHandler function:

$classifications = array();
$postfix = "";
$i = 0;
do {
  if ($i) $postfix = "@".$i;
  if (!$record["CLASSIFICATIONS/CLASSIFICATION".$postfix]) break;
  $name = $record["CLASSIFICATIONS/CLASSIFICATION".$postfix."-NAME"];
  $value = $record["CLASSIFICATIONS/CLASSIFICATION".$postfix];
  $classifications[$name] = $value;
  $i++;
} while(1);
// example usage after the above loop
print $classifications["Category"];
print $classifications["Work Type"];

Hope this helps!
Cheers,
David.

Submitted by mrtshaw on Mon, 2010-03-08 23:19

Thanks. All good now :)