mysql to xml (DOM question)

Posted by Jerry on Stack Overflow See other posts from Stack Overflow or by Jerry
Published on 2010-06-09T21:29:20Z Indexed on 2010/06/09 21:32 UTC
Read the original article Hit count: 288

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql