将mysql的数据转成xml

weijiepeng 2009-11-12 02:18:17
求个PHP类
...全文
227 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wisword 2009-11-13
  • 打赏
  • 举报
回复
在程序开头加上
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8");
} else {
header("Content-type: text/xml;charset=utf-8");
}
wisword 2009-11-13
  • 打赏
  • 举报
回复
/**
数组$result 是读取的数据表的内容,代码略。
**/
$dom = new DOMDocument('1.0','utf-8');
$dom->formatOutput =true;
$rootnode = $dom->appendChild($dom->createElement('rows'));

foreach ($result as $row)
{
$rownode = $rootnode->appendChild($dom->createElement('row'));
$rownode->setAttribute('id',$row['id']);
foreach ($row as $cell)
{
$cellnode = $rownode->appendChild($dom->createElement('cell'));
$txtnode = $cellnode->appendChild($dom->createCDATASection($cell));
}
}
echo $dom->saveXML();
babysc1 2009-11-13
  • 打赏
  • 举报
回复
存成数组转化xml
e4x法解析
phpboy 2009-11-13
  • 打赏
  • 举报
回复
就是生成 xml 好了

写个 函数不就OK了
jlzan1314 2009-11-13
  • 打赏
  • 举报
回复
xml只是一种格式和html一样.
v5_6000 2009-11-12
  • 打赏
  • 举报
回复
我还是喜欢用字符串操作。
xml也就是一段字符串罢了。做字符串替换然后输出最简单了。

echo "<root><title>".$title."</title></root>";
程序猿之殇 2009-11-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 weijiepeng 的回复:]
引用 1 楼 jakey9826 的回复:
需求不明确!



具体需求是 http方式  将一些数据返回xml给对方

首先 得将数据库的数据取出来后,转成xml,



[/Quote]
如果数据量不是很大的话,可以将数据存成数组,然后再将数组转成xml.
当然也可以循环取出再利用domxml等生成xml
v5_6000 2009-11-12
  • 打赏
  • 举报
回复
http://www.ibm.com/developerworks/cn/opensource/os-xmldomphp/
weijiepeng 2009-11-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jakey9826 的回复:]
需求不明确!
[/Quote]


具体需求是 http方式 将一些数据返回xml给对方

首先 得将数据库的数据取出来后,转成xml,


codeyell-com 2009-11-12
  • 打赏
  • 举报
回复
百度 google bing soso youdao gougou sogou
程序猿之殇 2009-11-12
  • 打赏
  • 举报
回复
需求不明确!

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧