title: Using PHP to write colons to XML
body: <p>I am trying to output an XML file from PhP using SimpleXML. I have run into problems with the ":" (colon) character. (Talk about art imitating life!)</p>
  
  <p><strong>Is there any way to escape the colon so I can add my elements to the object?</strong></p>
  
  <p>Here is my code:</p>
  
  <pre><code>$urlset-&gt;addAttribute('xmlns','http://www.sitemaps.org/schemas/sitemap/0.9');
  </code></pre>
  
  <p>This line passes okay, so it is only the attribute name that is failing, as in the below examples:</p>
  
  <pre><code>$urlset-&gt;addAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  $urlset-&gt;addAttribute('xsi:schemaLocation','http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd');
  </code></pre>
  
  <p>In each case, it lops off anything preceding the ":", like so:</p>
  
  <pre><code>&lt;urlset 
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
      xsi="http://www.w3.org/2001/XMLSchema-instance" 
      schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
  &gt;
  </code></pre>
  
  <p>Again, my problem is not with reading/parsing the ":" from XML, but with writing the ":" to XML from PHP. There is lots on parsing on the 'net, but I've found nothing on writing a ":" from PHP.</p>