XML with multiple roots
<p>Hi i've been trying to generate the following XML with PHP.</p>

<p>I've managed to generate it all except for the location section as it seems to treat it as another root and error out. Does anyone know the correct way to produce this?</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;classifieds xmlns="http://www.bdjjobs.com/ClassifiedJobFromRecruiterFeed"&gt;
    &lt;job&gt;
      &lt;reference_id&gt;20161114-72&lt;/reference_id&gt;
      &lt;recruiter&gt;Smiles R Us&lt;/recruiter&gt;
      &lt;job_title&gt;Denture Specialist&lt;/job_title&gt;
      &lt;short_description&gt;&lt;![CDATA[An exciting position in a dynamic dental practice]]&gt;&lt;/short_description&gt;
      &lt;description&gt;&lt;![CDATA[&lt;p&gt;Full description of post&lt;/p&gt;]]&gt;&lt;/description&gt;
      &lt;location&gt;
        &lt;city&gt;city&lt;/city&gt;
        &lt;state&gt;county&lt;/state&gt;
        &lt;country&gt;country&lt;/country&gt;
      &lt;/location&gt;
      &lt;salary_description&gt;&lt;![CDATA[Full Package]]&gt;&lt;/salary_description&gt;
      &lt;organisations&gt;Independent Dental Practice&lt;/organisations&gt;
      &lt;job_type&gt;Specialist Appointments&lt;/job_type&gt;
      &lt;salary_band&gt;£100,000 or more&lt;/salary_band&gt;
      &lt;contract_type&gt;Associate Permanent&lt;/contract_type&gt;
      &lt;hours&gt;Full time&lt;/hours&gt;
      &lt;practice_type&gt;Mixed (NHS/Private)&lt;/practice_type&gt;
      &lt;start_date&gt;2016-09-01&lt;/start_date&gt;
      &lt;expiry_date&gt;2016-10-30&lt;/expiry_date&gt;
      &lt;application_email&gt;apply_here@email.com&lt;/application_email&gt;
    &lt;/job&gt;
  &lt;/classifieds&gt;
</code></pre>

<p>Any assistance would be greatly appreciated, thanks :)</p>

<p>Here is the code:</p>

<pre><code>// Start Job Element
$job_element = $xml_document-&gt;createElement("job");

// Job ID
$rootreferencenumber = $xml_document-&gt;createElement("reference_id");
$rootreferencenumber-&gt;appendChild($xml_document-&gt;createCDATASection( get_the_ID() ));
$job_element-&gt;appendChild($rootreferencenumber);

// Recruiter
$recruiter = $xml_document-&gt;createElement("recruiter");
$recruiter-&gt;appendChild($xml_document-&gt;createCDATASection( "MBR Dental Recruitment" ));
$job_element-&gt;appendChild($recruiter);

// Job title
$title = $xml_document-&gt;createElement("title");
$title-&gt;appendChild($xml_document-&gt;createCDATASection( get_the_title() ) );
$job_element-&gt;appendChild($title);

// Job Description
$description = $xml_document-&gt;createElement("description");
$description-&gt;appendChild($xml_document-&gt;createCDATASection( ( strip_tags( str_replace( "&lt;/p&gt;", "\n\n", get_the_content() ) ) ) ) );
$job_element-&gt;appendChild($description);

// City
$city = $xml_document-&gt;createElement("city");
$get_city = explode( ',', get_post_meta( get_the_ID(), 'geolocation_city', true ) );
$city-&gt;appendChild($xml_document-&gt;createCDATASection( $get_city[0] ) );
$job_element-&gt;appendChild($city);

// Region from Taxonomy
$region = $xml_document-&gt;createElement("region");
$categories = wp_get_post_terms( get_the_ID(), 'job_listing_region', array( "fields" =&gt; "names" ) );
if ( $categories &amp;&amp; ! is_wp_error( $categories ) ) {
    $region-&gt;appendChild( $xml_document-&gt;createCDATASection( implode( ',', $categories ) ) );
} else {
    $region-&gt;appendChild( $xml_document-&gt;createCDATASection( '' ) );
}
$job_element-&gt;appendChild($region);


// Create Company Name
$company_name = $xml_document-&gt;createElement("organisations");
$company_name-&gt;appendChild($xml_document-&gt;createCDATASection('xx'));
$job_element-&gt;appendChild($company_name);

// Create Phone Number
$phone_number = $xml_document-&gt;createElement("phone_number");
$phone_number-&gt;appendChild($xml_document-&gt;createCDATASection('0000'));
$job_element-&gt;appendChild($phone_number);

// Job direct URL
$url = $xml_document-&gt;createElement("application_url");
$url-&gt;appendChild($xml_document-&gt;createCDATASection(get_permalink( get_the_ID() )));
$job_element-&gt;appendChild($url);

// Category
$phone_number = $xml_document-&gt;createElement("job_type");
$phone_number-&gt;appendChild($xml_document-&gt;createCDATASection('Job'));
$job_element-&gt;appendChild($phone_number);

// Subcategory
$region = $xml_document-&gt;createElement("subcategory");
$categories = wp_get_post_terms( get_the_ID(), 'job_listing_category', array( "fields" =&gt; "names" ) );
if ( $categories &amp;&amp; ! is_wp_error( $categories ) ) {
    $region-&gt;appendChild( $xml_document-&gt;createCDATASection( implode( ',', $categories ) ) );
} else {
    $region-&gt;appendChild( $xml_document-&gt;createCDATASection( '' ) );
}
$job_element-&gt;appendChild($region);


// Job date based on todays date
$date = $xml_document-&gt;createElement("start_date");
$date-&gt;appendChild($xml_document-&gt;createCDATASection(date(Ymd) ));
$job_element-&gt;appendChild($date);

// Job date expire from original post date
$expiry_date = $xml_document-&gt;createElement("expiry_date");
$wpDate = (date(Ymd) );
$wpDate = new DateTime($wpDate);
$wpDate-&gt;add(new DateInterval('P14D')); // P14D means a period of 14 days
$wpDate = $wpDate-&gt;format('Ymd');
$expiry_date-&gt;appendChild($xml_document-&gt;createCDATASection( $wpDate ));
$job_element-&gt;appendChild($expiry_date);

// Create Application Email Address
$app_email = $xml_document-&gt;createElement("application_email");
$app_email-&gt;appendChild($xml_document-&gt;createCDATASection('xx@xx.com'));
$job_element-&gt;appendChild($app_email);

// End Job Element
$root-&gt;appendChild($job_element);
</code></pre>