21,887
社区成员
发帖
与我相关
我的任务
分享
<?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;
?>
yum -y install php-dom
$dom = new DOMDocument('1.0', 'utf-8');
$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");
$Xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".Chr(10);
$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);
无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------
XML 文档必须有一个顶层元素。处理资源 http://....../1.php 时出错。
<?php
header("Content-Type: text/xml");
echo '<root><single><name>abc</name></single></root>';
?>
<?php
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;
?>