mysql to xml (DOM question)
- by Jerry
Hello guys
I am new to php dom and trying to get the mysql data transfer into xml. My current xml output is like this
<markers>
<city>
<name>Seattle</name>
<size>medium</size>
<name>New York</name>
<size>big</size>
<city>
<markers>
but I want to change it to
<markers>
<city>
<name>Seattle</name>
<size>medium</size>
<city>
<city>
<name>New York</name>
<size>big</size>
</city>
<city>
<markers>
my php
$dom=new DOMDocument("1.0");
$node=$dom->createElement("markers");
$parnode=$dom->appendChild($node);
$firstElement=$dom->createElement("city");
$parnode->appendChild($firstElement);
$getLocationQuery=mysql_query("SELECT * FROM location",$connection);
header("Content-type:text/xml");
while($row=mysql_fetch_assoc($getLocationQuery)){
foreach ($row as $fieldName=>$value){
$child=$dom->createElement($fieldName);
$value=$dom->createTextNode($value);
$child->appendChild($value);
$firstElement->appendChild($child);
}
}
I can't figure out how to change my php code. Please help me about it. Thanks a lot.