Есть xml который я разбираю XMLReader-ом и сохраняю данные в модель.
Но категории <category> у меня почему то каждая нижняя вакансия наследует категории верхней вакансии
Код: Выделить всё
<vacancy>
<url>https://example.com</url>
<creation-date>2017-10-24 10:55:07 GMT+2</creation-date>
<update-date>2017-11-15 14:43:33 GMT+2</update-date>
<salary>20000</salary>
<currency>UAH</currency>
<category>
<industry>Домашний сервис</industry>
</category>
<category>
<industry>Ремонт техники и предметов быта</industry>
</category>
<category>
<industry>Сельское хозяйство, агробизнес</industry>
</category>
<job-name>Помощники с проживанием</job-name>
<employment>полная</employment>
<description>.....................................</description>
<requirement>
<education>среднее</education>
<experience>не требуется</experience>
</requirement>
<addresses>
<address>
<location>Украина, Киев</location>
</address>
</addresses>
<company>
<name>Test</name>
<logo>url</logo>
<contact-name>ваваав</contact-name>
<hr-agency>false</hr-agency>
</company>
</vacancy>
<vacancy>
<url>https://example.com</url>
<creation-date>2017-10-24 10:58:28 GMT+2</creation-date>
<update-date>2017-11-15 14:43:31 GMT+2</update-date>
<salary>15000</salary>
<currency>UAH</currency>
<category>
<industry>Домашний сервис</industry>
</category>
<category>
<industry>Сельское хозяйство, агробизнес</industry>
</category>
<category>
<industry>Строительство, архитектура</industry>
</category>
<job-name>Ссадовник- хозяйственник</job-name>
<employment>полная</employment>
<description>Садовник ...................</description>
<requirement>
<education>среднее</education>
<experience>не требуется</experience>
</requirement>
<addresses>
<address>
<location>Украина, Киев</location>
</address>
</addresses>
<company>
<name>N</name>
<logo>N</logo>
<contact-name>N</contact-name>
<hr-agency>false</hr-agency>
</company>
</vacancy>
Код: Выделить всё
$reader = new XMLReader;
$reader->open($jobsfile);
while($reader->read()) {
if($reader->nodeType == XMLReader::ELEMENT) {
$data = array();
if ($reader->localName == 'vacancy') {
$data['category'] = [];
$data['city'] = [];
while($reader->read()) {
if ($reader->localName == 'industry') {
$reader->read();
if ($reader->nodeType == XMLReader::TEXT) {
$data['category'][] = $reader->value;
}
}
if ($reader->localName == 'location') {
$reader->read();
if ($reader->nodeType == XMLReader::TEXT) {
$data['city'][] = $reader->value;
}
}
//**** Other attributes
}
}
if (count($data)){
//Save in model
}
}
}