【发布时间】:2012-11-25 11:59:54
【问题描述】:
XML 文件有问题。 我在互联网上搜索并找到了很多关于我的问题的示例,但我不是 XML 文件方面的专家,也无法解决我的问题。我想做 XML 文件并像 RSS FEED 一样工作。因此,我从数据库中获取数据并尝试创建 xml 代码。这是我的 php 文件中的内容 (并且因为这个问题没有验证:Undefined root element: channel)
<?php
include "connection.php";
//create the table with the fields
$rss_table = array();
$query = mysql_query("SELECT * FROM rssfeeds");
while($values_query = mysql_fetch_assoc($query))
{
$rss_table [] = array(
'title' => $values_query['title'],
'description' => $values_query['summary'],
'link' => $values_query['link']
);
}
$doc = new DOMDocument();
$doc->formatOutput = true;
$doc->encoding = "utf-8";
$r = $doc->createElement( "channel" );
$doc->appendChild( $r );
//$i=0;
foreach( $rss_table as $rss )
{
$b = $doc->createElement( "item" );
$title = $doc->createElement( "title" );
$title->appendChild(
$doc->createTextNode( $rss['title'] )
);
$b->appendChild( $title );
$description = $doc->createElement( "description" );
$description->appendChild(
$doc->createTextNode( $rss['description'] )
);
$b->appendChild( $description );
$link = $doc->createElement( "link" );
$link->appendChild(
$doc->createTextNode( $rss['link'] )
);
$b->appendChild( $link );
$r->appendChild( $b );
}
echo $doc->saveXML();
$doc->save("rssfeeds.xml")
?>
我想要标题 - 链接 - 描述 简单的...仅此而已
这是我在 rssfeeds.xml 文件中得到的内容:
<?xml version="1.0" encoding="utf-8"?>
<channel>
<item>
<title>winter week</title>
<description>You can come as you are! </description>
<link>http://tdm2000international.org/tdm2000international/news.php</link>
</item>
<item>
<title>Greek night</title>
<description>elliniki bradua sto magazi</description>
<link>http://tdm2000international.org/tdm2000international/news.php</link>
</item>
<item>
<title>event website</title>
<description>first of december, how is it going?</description>
<link>http://tdm2000international.org/tdm2000international/news.php</link>
</item>
</channel>
不错的格式,但它有问题。我不明白问题出在哪里。 任何帮助将不胜感激
(我也在这个网站上查看任何解决方案,但我找不到我的解决方案..所以,很抱歉这篇文章,如果它已经存在的话)
【问题讨论】:
-
它有什么问题?
-
你怎么知道有问题?
-
and it is not validated because of this problem: Undefined root element: channel是什么意思?!除非您有 XML 文档的架构,否则它不会被定义。 -
我有 FeedDemon 程序并说这个 RSS 链接不起作用.. 我把这个 RSS 链接放在这里:validator.w3.org/feed 它说:未定义的根元素:频道你是什么意思,除非我有你的 xml 文档的架构,它不会被定义?