I am currently trying to use the expat xml functions in php to parse xml generated via XML_Serializer from PEAR. However the generated xml has whitespace for the first 14 lines and causes this error
XML error: xml declaration not at start of external entity at line 16
here is the serializer code
function set_xml_serialise()
{
// include class file
include("Serializer.php");
// create object
$serializer = new XML_Serializer();
mysql_data_seek($this->results, 0); // set to beginning
// iterate through rows and print column data
while ($row = mysql_fetch_array($this->results))
{
$xml[] = array ( "product_id" => $row[0],
"short_desc" => $row[1],
"long_desc" => $row[2],
"unit_price" => $row[3],
"product_group_id" => $row[4],
"product_sub_group_id" => $row[5],
"updated_last" => $row[6],
"keywords" => $row[7],);
}
$serializer->setOption("addDecl", true); // add XML declaration
$serializer->setOption("indent", " "); // indent elements
$serializer->setOption("defaultTagName", "product"); // set default tag
$serializer->setOption("rootName", "product_info"); // set name for root element
$result = $serializer->serialize($xml); // perform serialization
if($result === true) // check result code and set XML if success
{
$this->xml_serialised = $serializer->getSerializedData();
}
If i save the xml without the whitespace and parse it, it works fine. Could anyone tell me how to solve this.
thanks in advance