# XML, PHP and looping

**URL:** <https://forum.kirupa.com/t/xml-php-and-looping/209787>\
**Category:** programming\
**Created:** [December 12, 2006, 1:37pm UTC](https://forum.kirupa.com/t/xml-php-and-looping/209787 "2006-12-12T13:37:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laalun](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@Laalun](https://forum.kirupa.com/u/Laalun)\
**Post date:** [December 12, 2006, 1:37pm UTC](https://forum.kirupa.com/t/xml-php-and-looping/209787/1 "2006-12-12T13:37:05Z")

</div>

Hi,  
I’m a bit stuck with a XML document I have. I can loop through the top level nodes and get the data out ok, but one of these nodes has more nodes inside it, and this has me puzzled.  
The XML is basically a list of employees, with each employee having a code, type, location and a history, which consists of a list of jobs, each with start and end date.Here’s an example.

```auto

[COLOR=#0000ff][COLOR=#0000ff]<employees[/COLOR]>[/COLOR]
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]employee[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]empcode[/COLOR][COLOR=#0000ff]>[/COLOR] **1** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]empcode[/COLOR][COLOR=#0000ff]>[/COLOR] 
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]type[/COLOR][COLOR=#0000ff]>[/COLOR] **Manager** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]type[/COLOR][COLOR=#0000ff]>[/COLOR] 
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]location[/COLOR][COLOR=#0000ff]>[/COLOR] **London** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]location[/COLOR][COLOR=#0000ff]>[/COLOR] 
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]history[/COLOR][COLOR=#0000ff]>[/COLOR]
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] **29-10-2006** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] 
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] **31-10-2006** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] 
   [COLOR=#0000ff]</[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] **12-11-2006** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] 
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] **14-11-2006** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] 
[COLOR=#0000ff]</[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] **08-04-2007** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] 
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] **10-04-2007** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] 
 [COLOR=#0000ff]</[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
[COLOR=#0000ff]</history>[/COLOR]
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]employee[/COLOR][COLOR=#0000ff]>[/COLOR]
[COLOR=#0000ff]<[/COLOR][COLOR=#990000]employee[/COLOR][COLOR=#0000ff]>[/COLOR] 
[COLOR=#0000ff]<[/COLOR][COLOR=#990000]empcode[/COLOR][COLOR=#0000ff]>[/COLOR] **2** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]empcode[/COLOR][COLOR=#0000ff]>[/COLOR] 
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]type[/COLOR][COLOR=#0000ff]>[/COLOR] **PA** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]type[/COLOR][COLOR=#0000ff]>[/COLOR] 
[COLOR=#0000ff]<[/COLOR][COLOR=#990000]location[/COLOR][COLOR=#0000ff]>[/COLOR] **NYC** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]location[/COLOR][COLOR=#0000ff]>[/COLOR] 
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]history[/COLOR][COLOR=#0000ff]>[/COLOR]
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] **15-01-2003** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR]
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] **31-10-2004** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] 
[COLOR=#0000ff]</[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
[**[FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT]**](file:///U:/local-html/ukholidays/holidays.xml#) [COLOR=#0000ff]<[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
    [COLOR=#0000ff]<[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] **12-11-2006** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] **14-11-2006** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] 
[COLOR=#0000ff]</[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
[COLOR=#0000ff]<[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] **08-04-2007** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]startdate[/COLOR][COLOR=#0000ff]>[/COLOR] 
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] **10-04-2007** [COLOR=#0000ff]</[/COLOR][COLOR=#990000]enddate[/COLOR][COLOR=#0000ff]>[/COLOR] 
[COLOR=#0000ff]</[/COLOR][COLOR=#990000]job[/COLOR][COLOR=#0000ff]>[/COLOR]
[COLOR=#0000ff]</history>[/COLOR]
[COLOR=#0000ff]</[/COLOR][COLOR=#990000]employee[/COLOR][COLOR=#0000ff]>[/COLOR]
[COLOR=#0000ff][COLOR=#0000ff][COLOR=#0000ff]</employees[/COLOR]>[/COLOR][/COLOR]

```

The problem I am trying to solve is looping through the history of each employee and getting the data out. The history could have little or many jobs in.

Any pointers? Cheers.
