我必须按照代码将数据上传到第三方。但是,当我在验证器中测试时,我收到以下错误:
Undefined root elements:items and text/xml media type is not specific enough.
我不知道我需要改变什么。
以下是代码:
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>
<items>';
mysql_select_db($database_dconn, $dconn);
$query_feed = "SELECT * FROM dat_table WHERE time BETWEEN (NOW() - INTERVAL 7 DAY) AND NOW()";
$feed = mysql_query($query_feed, $dconn) or die(mysql_error());
while ($row_feed = mysql_fetch_assoc($feed)){
echo'<item>
<name>'.$row_feed['Name'].'</name>
<email>'.$row_feed['email'].'</email>
<date>'.$row_feed['Date'].'</date>
<description>'.$row_feed['Make'].' '.$row_feed['Model'].' '.$row_feed['Type'].'</description>
<logon>'.$row_feed['Logon'].'</logon>
<category>'.$row_feed['Type'].'/'.$row_feed['Make'].'</category>
<product_search_code>'.$row_feed['Product_search_code'].'</product_search_code>
<order_ref>'.$row_feed['Invoice'].'</order_ref>
<product_link>'.$row_feed['Product_link'].'</product_link>
<customer_ref>'.$row_feed['Invoice'].'</customer_ref>
<amount>'.$row_feed['Price'].'</amount>
<currency>GBP</currency>
</item>';
}
echo '</items>
';
这是RSS输出验证器:
<?xml version="1.0" encoding="UTF-8"?>
<items><item>
<name>Name of customer</name>
<email>customer@gmail.com</email>
<date>03/04/2014</date>
<description>Roland FP80BK Piano</description>
<logon>www.pianoandkeyboardshoponline.co.uk</logon>
<category>Piano/Roland</category>
<product_search_code>264</product_search_code>
<order_ref>8336</order_ref>
<product_link>http://www.pianoandkeyboardshop.co.uk/Roland-FP80-Digital-Piano-in-Satin-Black/264</product_link>
<customer_ref>8336</customer_ref>
<amount>1500.00</amount>
<currency>GBP</currency>
</item><item>
next item etc
---
--
</item><items>
非常感谢任何帮助。
答案 0 :(得分:0)
text / xml内容类型用于通用XML文档。对于Feed,请尝试使用
header('Content-Type: application/rss+xml');
但无论如何,为了创建有效的RSS,你必须使用正确的RSS标签(类似this之类的东西)。你似乎使用了很多自定义标签,所以我不知道你到底需要做什么。最简单的解决方案是为自定义标记使用名称空间,例如:
header('Content-Type: application/rss+xml');
echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:mytags="http://mytags.something.net">
<channel>
<title>My RSS Title</title>
<description>This is the description for my RSS feed</description>
<link>http://www.someexamplerssdomain.com/main.html</link>
<mytags:items>';
mysql_select_db($database_dconn, $dconn);
$query_feed = "SELECT * FROM dat_table WHERE time BETWEEN (NOW() - INTERVAL 7 DAY) AND NOW()";
$feed = mysql_query($query_feed, $dconn) or die(mysql_error());
while ($row_feed = mysql_fetch_assoc($feed)){
echo '<mytags:item>
<mytags:name>'.$row_feed['Name'].'</mytags:name>
<mytags:email>'.$row_feed['email'].'</mytags:email>
<mytags:date>'.$row_feed['Date'].'</mytags:date>
<mytags:description>'.$row_feed['Make'].' '.$row_feed['Model'].' '.$row_feed['Type'].'</mytags:description>
<mytags:logon>'.$row_feed['Logon'].'</mytags:logon>
<mytags:category>'.$row_feed['Type'].'/'.$row_feed['Make'].'</mytags:category>
<mytags:product_search_code>'.$row_feed['Product_search_code'].'</mytags:product_search_code>
<mytags:order_ref>'.$row_feed['Invoice'].'</mytags:order_ref>
<mytags:product_link>'.$row_feed['Product_link'].'</mytags:product_link>
<mytags:customer_ref>'.$row_feed['Invoice'].'</mytags:customer_ref>
<mytags:amount>'.$row_feed['Price'].'</mytags:amount>
<mytags:currency>GBP</mytags:currency>
</mytags:item>';
}
echo '</mytags:items>
</channel>
</rss>';
答案 1 :(得分:0)
您没有定义xmlns(XML名称空间)。因此,错误可能是由于根元素 items 未定义,如错误消息中所述。有关xmlns的说明,请参阅this link或that link。
首先,要完成上一个答案,在第一个回显之后,添加一个特定于rss的行:echo '<rss version="2.0">';
其次,您需要在上面的行echo '<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">';
中添加xmlns定义,或者更改根元素名称。尝试使用频道或 Feed 。更好的是,找到您希望阅读您的Feed的服务所读取的Feed,并查看文件的开头;寻找xmlns和根元素名称。
最好的,