In the SimpleXml PHP manual someone gave a good example in the comments section.
Here is how I got it to work.
Say you have the following XML in a file xml.php:
<?php
$string = <<<XML
<Row>
<Cell>
<Data>Dolly Parton</Data>
</Cell>
<Cell>
<Data>Islands in the Stream</Data>
</Cell>
<Cell>
<Data>what</Data>
</Cell>
<Cell>
<Data>1-29-2010</Data>
</Cell>
</Row>
XML;
You can read in this file and add the attributes you want by using XPath.
<?php
include("xml.php");
$sxe = new SimpleXMLElement($string);
$data = $sxe->xpath('//Data');
foreach ($data as $value)
{
$value->addAttribute('ss:Type', 'String', 'http://www.w3.org/2001/XMLSchema-instance');
}
echo $sxe->asXML();
?>
This is the output I get:
<Row>
<Cell>
<Data xmlns:ss="http://www.w3.org/2001/XMLSchema-instance" ss:Type="String">Dolly Parton</Data>
</Cell>
<Cell>
<Data xmlns:ss="http://www.w3.org/2001/XMLSchema-instance" ss:Type="String">Islands in the Stream</Data>
</Cell>
<Cell>
<Data xmlns:ss="http://www.w3.org/2001/XMLSchema-instance" ss:Type="String">what</Data>
</Cell>
<Cell>
<Data xmlns:ss="http://www.w3.org/2001/XMLSchema-instance" ss:Type="String">1-29-2010</Data>
</Cell>
</Row>