I have the following code
<?php
$precinct = '0015A';
$contested = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
$contested .= "<contested_races><info>CONTESTED RACES FOR PRECINCT ".
$precinct."</info><entries></entries></contested_races>";
$xml = new SimpleXmlElement($contested);
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $connection))
//select database into variable
$query = "select contested_title, candidate, party from contested order by contested_id;";
$result = $query($query) or die(mysql_error());
while($row = mysql_fetch_row($result)){
$entry = $xml->entries->addChild("entry");
$entry->addAttribute("title", $row[0]);
$entry->addAttribute("candidate", $row[1]);
$entry->addAttribute("party", $row[2]);
}
echo $xml->asXML();
?>
The resulting XML looks like this:
<contested_races>
<info>CONTESTED RACES FOR PRECINCT 0015A</info>
<entries>
<entry title="PRESIDENT AND VICE PRESIDENT" candidate="John McCain" party="REP"/>
<entry> title="PRESIDENT AND VICE PRESIDENT" candidate="Sarah Palin" party="REP"/>
<entry> title="PRESIDENT AND VICE PRESIDENT" candidate="Barack Obama" party="DEM"/>
<entry> title="PRESIDENT AND VICE PRESIDENT" candidate="Joe Biden" party="DEM"/>
</entries>
</contested_races>
The first node looks correct (<entry title="...) but subsequent nodes have the
node name enclosed before the attribute starts (<entry> title="...).
The nodes all are terminated correctly.
I am using PHP5.3.0.
Any ideas?