问题可能比较弱,之前碰到过,但实在想不起来了,只好求助大家<?php
header("Content-Type:text/xml");
$dom=new DOMDocument('1.0','utf-8');
$root=$dom->createElement('root');
$dom->appendChild($root);
$xmlStr=$dom->saveXML();
echo $xmlStr;
?>IE上无法显示 XML 页,报 XML 文档必须有一个顶层元素。不知道是不是php文件格式BOM的问题,但改成无BOM utf-8,还是不行。
不知道和后台php,apache是否有关十分感谢
header("Content-Type:text/xml");
$dom=new DOMDocument('1.0','utf-8');
$root=$dom->createElement('root');
$dom->appendChild($root);
$xmlStr=$dom->saveXML();
echo $xmlStr;
?>IE上无法显示 XML 页,报 XML 文档必须有一个顶层元素。不知道是不是php文件格式BOM的问题,但改成无BOM utf-8,还是不行。
不知道和后台php,apache是否有关十分感谢
今天按照那个例子重写,然后上传的本地服务器上,就无法显示。会不会和环境和文件格式有关?
header("Content-Type:text/xml");
$dom=new DOMDocument('1.0','utf-8');
$root=$dom->createElement('root');
$dom->appendChild($root);
$single=$dom->createElement('single');
$root->appendChild($single);
$name=$dom->createElement('name');
$single->appendChild($name);
$nameContent=$dom->createTextNode('abc');
$name->appendChild($nameContent);
$xmlStr=$dom->saveXML();
echo $xmlStr;
?>这是原来程序的一部分,我放在本地服务器上,同样的错误
有个小例子
header("Content-Type: text/xml");
echo '<root><single><name>abc</name></single></root>';
?>应该不是服务器的问题,直接输出,又可以显示了,用dom操作,就不行,问题出在哪里呢?
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------
XML 文档必须有一个顶层元素。处理资源 http://....../1.php 时出错。1.用dom操作的方法,同样的代码,在本机windows+apache+php下,就可以正常输出;
而在服务器上,linux+apache+php,就不能输出,(php5.1,phpinfo都是支持xml的)。2.用echo直接输出,本机和服务器上,都可以输出xml。3.用了别人和手册上的范例,服务器上依然无法输出。
初步判断是可能是linux,php环境的问题,但是php5.1.6是支持xml的,而且phpinfo中都是可用的。
本人是用ultraedit编辑php,难道和php文件格式(utf-8,无BOM)之类的有关?请高人指点。
$Xml.= " <urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">".Chr(10);
$Xml.= " <url>".Chr(10);
$Xml.= " <loc>".$Fle."</loc>".Chr(10);
$Xml.= " <lastmod>".now("Y-m-d",$val[0])."</lastmod>".Chr(10);
$Xml.= " <changefreq>$changefreq</changefreq>".Chr(10);
$Xml.= " <priority>$priority</priority>".Chr(10);
$Xml.= " </url>".Chr(10).Chr(10);
$i++;
$Xml.= " </urlset>"; File_Put_Contents("../sitemaps.xml",$Xml,LOCK_EX);
$rootnode = $dom->appendChild(new DOMElement('Order'));
$rootnode->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootnode->setAttribute('saveDate', date("Y-m-d H:i:s"));
//iconv(srctype,dsttype,str)函数用于转换编码
$rootnode->appendChild(new DOMElement("orderId", iconv("UTF-8", "GBK", $insertId)));
$rootnode->appendChild(new DOMElement("orderPrice", iconv("UTF-8", "GBK//IGNORE",
$ordPri)));
$rootnode->appendChild(new DOMElement("userId", iconv("UTF-8", "GBK//IGNORE", $ordMemId)));
$rootnode->appendChild(new DOMElement("userName", iconv("UTF-8", "GBK//IGNORE",
$ordMemNick))); $goodsList = $rootnode->appendChild(new DOMElement(iconv("UTF-8", "GBK//IGNORE",
"goodsList")));
foreach ($objOrdCon as $key => $good) {
$goodcur = $goodsList->appendChild(new DOMElement(iconv("UTF-8", "GBK//IGNORE",
'good')));
$goodcur->setAttribute('goodName', iconv("UTF-8", "GBK//IGNORE", $good->godnam));
$goodcur->setAttribute('goodId', iconv("UTF-8", "GBK//IGNORE", $good->godid));
$goodcur->setAttribute('goodPrice', iconv("UTF-8", "GBK//IGNORE", $good->godpri));
$goodcur->appendChild(new DOMElement('quantity', iconv("UTF-8", "GBK//IGNORE", $good->
godnum)));
$goodcur->appendChild(new DOMElement('subtotal', iconv("UTF-8", "GBK//IGNORE", ($good->
godnum * $good->godpri))));
}
$dom->save("cart.$insertId.xml");