dongxiong2000 2013-02-23 05:49
浏览 16

Mysql To Xml输出页面[关闭]

I'm trying to output various tables from my database but I can't seem to figure out how to perform what i had in mind.

I want to output my data like this.

<locations>
    <destination>
       <name>A</name>
       <address>B</name>
    </destination>

    <destination>
       <name>C</name>
       <address>D</name>
    </destination>
</locations>

so far i have this as output.

 <Locations>
<destination name="burlo"/>
<destination name="Raymund"/>
<destination name="Bacolod City"/>
<destination name="Victorias"/>
<destination name="Sipalay"/>
<destination name="Ambot"/>
<destination name="aweawea"/>
<destination name="ilo-ilo"/>
<destination name="ilo-ilo"/>
<destination name="Hinobaan"/>
<destination name="heart"/>
<destination name="heart"/>
<destination name="heart"/>
<destination name="heart"/>
<destination name="heart"/>
<destination name="Daddy"/>
<destination name="aguisan"/>
</Locations>

This is how i generate them.

// Start XML file, create parent node


$dom = new DOMDocument("1.0");
$node = $dom->createElement("Locations");
$parnode = $dom->appendChild($node); 

// Select all the rows in the markers table

$query = "SELECT  * FROM tbl_locations where status='active'";
$result = mysql_query($query);
if (!$result) {  
  die('Invalid query: ' . mysql_error());
} 

header("Content-type: text/xml"); 

// Iterate through the rows, adding XML nodes for each

while ($row = @mysql_fetch_assoc($result)){  
  // ADD TO XML DOCUMENT NODE  

  $node = $dom->createElement("destination");  

  $newnode = $parnode->appendChild($node);   
  $newnode->setAttribute("name",$row['name']);




} 

echo $dom->saveXML();

?>

Would appreciate any help.

  • 写回答

3条回答 默认 最新

  • douyi9705 2013-02-23 05:55
    关注

    Do this

    $node = $dom->createElement("destination");  
    $newnode = $parnode->appendChild($node);  
    $node1 = $dom->createElement("name");   
    $newnode = $parnode->appendChild($node1);  
    $newnode->insertData(0,$row['name']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致