title: Invalid characters appearing at random in XML output, including within the tags
body: <p>I have a php script which generates an XML document, however there is a strange problem with the output.</p>
  
  <p>I'm getting invalid characters seemingly at random throughout the document, even in the tags themselves? For example:</p>
  
  <pre><code>&lt;id&gt;&lt;![CATA[JS-DWLG001]]&gt;&lt;/id&gt;
  </code></pre>
  
  <p>I'm not sure how this will render in your browser, so if you can't see it, the invalid character is replacing the 'D' in 'CDATA'.</p>
  
  <p>Any ideas?</p>
  
  <p>EDIT: Here's the business bit of the code to generate the xml:</p>
  
  <pre><code>&lt;?
  // variables and arrays populated here from db
  ?&gt;
  
  &lt;job&gt;
                  &lt;title&gt;&lt;![CDATA[&lt;?=$field['vac_Title']?&gt;]]&gt;&lt;/title&gt;
                  &lt;date&gt;&lt;![CDATA[&lt;?=date("D, j M Y g:i:s",$stamp)." GMT"?&gt;&gt;]]&gt;&lt;/date&gt;
                  &lt;referencenumber&gt;&lt;![CDATA[&lt;?=$field['vac_Ref']?&gt;]]&gt;&lt;/referencenumber&gt;
                  &lt;url&gt;&lt;![CDATA[&lt;?=site_URL.parse_job_path($field['vac_Title'],$key)?&gt;]]&gt;&lt;/url&gt;
                  &lt;company&gt;&lt;![CDATA[&lt;?=$field['vac_advertiser_name']?&gt;]]&gt;&lt;/company&gt;
                  &lt;city&gt;&lt;![CDATA[]]&gt;&lt;/city&gt;
                  &lt;state&gt;&lt;![CDATA[&lt;?=$field['vac_locs']?&gt;]]&gt;&lt;/state&gt;
                  &lt;country&gt;&lt;![CDATA[UK]]&gt;&lt;/country&gt;
                  &lt;postalcode&gt;&lt;![CDATA[]]&gt;&lt;/postalcode&gt;
                  &lt;description&gt;&lt;![CDATA[&lt;?=$field['vac_Description']?&gt;]]&gt;&lt;/description&gt;
                  &lt;salary&gt;&lt;![CDATA[&lt;?-$field['vac_Salary-Range']?&gt;]]&gt;&lt;/salary&gt;
                  &lt;education&gt;&lt;![CDATA[&lt;?=$education_level?&gt;&gt;]]&gt;&lt;/education&gt;
                  &lt;jobtype&gt;&lt;![CDATA[&lt;?=$emp_type?&gt;]]&gt;&lt;/jobtype&gt;
                  &lt;category&gt;&lt;/category&gt;
                  &lt;experience&gt;&lt;/experience&gt;
              &lt;/job&gt;
  </code></pre>