php输出xml 类型为text/xml 怎么进入xml模式
<?phpheader("Content-type:text/xml");echo"<?xmlversion=\"1.0\"encoding=\"GB2312\"\n";...
<?php
header("Content-type:text/xml");
echo "<?xml version=\"1.0\" encoding=\"GB2312\"\n";
?>
这里都写了
但是还是显示的是text/html
如何解决? 展开
header("Content-type:text/xml");
echo "<?xml version=\"1.0\" encoding=\"GB2312\"\n";
?>
这里都写了
但是还是显示的是text/html
如何解决? 展开
2个回答
展开全部
<?php
/*
写入xml文件
*/
mysql_connect('localhost','root','');
mysql_query("set names utf8");
mysql_select_db('1012javab');
$result = mysql_query("select * from goods");
while($a = mysql_fetch_assoc($result)){
$arr[] = $a;
}
// 实例化一个dom对象
$doc = new DOMDocument;
// 格式化输入
$doc->formatOutput = true;
// 创建一个根节点
$books = $doc->createElement('books');
// 添加元素节点
$books = $doc->appendChild($books);
/*
$books = $doc->appendChild($books);
$book = $doc->createElement('book');
$books->appendChild($book);
$title = $doc->createElement('ttt');
$book->appendChild($title);
*/
foreach($arr as $key=>$val){
echo 11;
$book = $doc->createElement('book');
foreach($val as $key1=>$val1){
###########################第一组
$title = $doc->createElement($key1);
// 创建一个文件节点
$content = $doc->createTextNode($val1);
$title->appendChild($content);
$book->appendChild($title);
}
$books->appendChild($book);
}
if($doc->save('goods.xml')){
echo 'yes';
}else{
echo 'no';
}
/*
$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;
$root = $doc->createElement('book');
$root = $doc->appendChild($root);
$title = $doc->createElement('title');
$title = $root->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
echo "Saving all the document:\n";
echo $doc->saveXML() . "\n";
echo "Saving only the title part:\n";
echo $doc->saveXML($title);
*/
?>
/*
写入xml文件
*/
mysql_connect('localhost','root','');
mysql_query("set names utf8");
mysql_select_db('1012javab');
$result = mysql_query("select * from goods");
while($a = mysql_fetch_assoc($result)){
$arr[] = $a;
}
// 实例化一个dom对象
$doc = new DOMDocument;
// 格式化输入
$doc->formatOutput = true;
// 创建一个根节点
$books = $doc->createElement('books');
// 添加元素节点
$books = $doc->appendChild($books);
/*
$books = $doc->appendChild($books);
$book = $doc->createElement('book');
$books->appendChild($book);
$title = $doc->createElement('ttt');
$book->appendChild($title);
*/
foreach($arr as $key=>$val){
echo 11;
$book = $doc->createElement('book');
foreach($val as $key1=>$val1){
###########################第一组
$title = $doc->createElement($key1);
// 创建一个文件节点
$content = $doc->createTextNode($val1);
$title->appendChild($content);
$book->appendChild($title);
}
$books->appendChild($book);
}
if($doc->save('goods.xml')){
echo 'yes';
}else{
echo 'no';
}
/*
$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;
$root = $doc->createElement('book');
$root = $doc->appendChild($root);
$title = $doc->createElement('title');
$title = $root->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
echo "Saving all the document:\n";
echo $doc->saveXML() . "\n";
echo "Saving only the title part:\n";
echo $doc->saveXML($title);
*/
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询