- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在制作一个 Web 应用程序,它从网站(URL 在数据库中)获取 RSS 提要,然后将它们加载到我的 Web 应用程序中。但是我收到了这个错误
System.Xml.XmlException: Root element is missing. root element is missing. at line : rssdoc.load(rssStream);
异常详细信息:System.Xml.XmlException:存在多个根元素。第 2 行,位置 2。那么如何通过单个 xml 元素封装其他所有内容
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Net;
using System.Text;
using System.IO;
using System.Data;
using System.Data.SqlClient;
public partial class poletics : System.Web.UI.Page
{
public SqlConnection oldbcon = new SqlConnection();
static int n = 0;
static DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
oldbcon = opncon();
using (oldbcon)
{
SqlDataAdapter ad = new SqlDataAdapter("SELECT * from LebPolRss", oldbcon);
ad.Fill(dt);
}
int f = 3;
while (n < f)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Literal feed = new Literal();
try
{
feed.Text = ProcessRss(dt.Rows[i][3].ToString(), dt.Rows[i][4].ToString());
}
catch (WebException ex)
{
WebResponse response = ex.Response;
}
Panel1.Controls.Add(feed);
}
n++;
}
}
public static string ProcessRss(string rssUrl, string feed)
{
WebRequest request = WebRequest.Create(rssUrl);
WebResponse response = request.GetResponse();
StringBuilder sb = new StringBuilder("");
Stream rssStream = response.GetResponseStream();
XmlDocument rssDoc = new XmlDocument();
rssDoc.Load(rssStream);//here is the line where the exception thrown
XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");
string title = "";
string link = "";
string description = "";
int upperlimit = rssItems.Count;
if (upperlimit > n)
upperlimit = n + 1;
if (upperlimit > 0)
{
sb.Append("<ul>");
for (int i = 0; i < upperlimit - n; i++)
{
XmlNode rssDetail;
rssDetail = rssItems.Item(i + n).SelectSingleNode("title");
if (rssDetail != null)
{
if (feed.ToString().Equals("tayyar"))
{
title = rssDetail.InnerText.Substring(5);
}
else
{
if (rssDetail.InnerText.Length > 75)
{
title = rssDetail.InnerText.Substring(0, 75);
}
else
{
title = rssDetail.InnerText;
}
}
}
else
{
title = "";
}
rssDetail = rssItems.Item(i + n).SelectSingleNode("link");
if (rssDetail != null)
{
if (feed.ToString().Equals("tayyar"))
{
if (rssDetail.InnerText.Substring(0, 21).CompareTo("http://www.tayyar.org") != 0)
{
link = "http://www.tayyar.org" + rssDetail.InnerText;
}
else
{
link = rssDetail.InnerText;
}
}
else
{
link = rssDetail.InnerText;
}
}
else
{
link = "";
}
rssDetail = rssItems.Item(i + n).SelectSingleNode("description");
if (rssDetail != null)
{
if (!rssDetail.InnerText.Substring(3, 3).Equals("Ad:"))
{
description = rssDetail.InnerText;
}
}
else
{
description = "";
}
switch (feed)
{
case "tayyar": sb.Append("<div class='imgsep'><li><img src='logos/tayyar.jpg' width='50px' height='30px'/> <a href='" + link + "' target='_blank'>" + title + "</a> <img src='Images/smallarrow.png'/></li></div>");
break;
case "14march": sb.Append("<div class='imgsep'><li><img src='logos/14march.jpg' width='50px' height='30px'/> <a href='" + link + "' target='_blank'>" + title + "</a> <img src='Images/smallarrow.png'/></li></div>");
break;
case "annahar": sb.Append("<div class='imgsep'><li><img src='logos/annahar.jpg' width='50px' height='30px'/> <a href='" + link + "' target='_blank'>" + title + "</a> <img src='Images/smallarrow.png'/></li></div>");
break;
case "alakhbar": sb.Append("<div class='imgsep'><li><img src='logos/akhbar.jpg' width='50px' height='30px'/> <a href='" + link + "' target='_blank'>" + title + "</a> <img src='Images/smallarrow.png'/></li></div>");
break;
case "sadabeirut": sb.Append("<div class='imgsep'><li><img src='logos/echobeirut.png' width='50px' height='30px'/> <a href='" + link + "' target='_blank'>" + title + "</a> <img src='Images/smallarrow.png'/></li></div>");
break;
case "assafir": sb.Append("<div class='imgsep'><li><img src='logos/assafir.png' width='50px' height='30px'/> <a href='" + link + "' target='_blank'>" + title + "</a> <img src='Images/smallarrow.png'/></li></div>");
break;
case "aliwaa": sb.Append("<div class='imgsep'><li><img src='logos/aliwaa.jpg' width='50px' height='30px'/> <a href='" + link + "' target='_blank'>" + title + "</a> <img src='Images/smallarrow.png'/></li></div>");
break;
}
}
sb.Append("</ul>");
}
return sb.ToString();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
oldbcon = opncon();
using (oldbcon)
{
SqlDataAdapter ad = new SqlDataAdapter("SELECT * from LebPolRss", oldbcon);
ad.Fill(dt);
}
n = 4;
for (int i = 0; i < dt.Rows.Count; i++)
{
Literal feed = new Literal();
try
{
feed.Text = ProcessRss(dt.Rows[i][3].ToString(), dt.Rows[i][4].ToString());
}
catch (WebException ex) { WebResponse response = ex.Response; }
Panel1.Controls.Add(feed);
}
LinkButton1.Visible = false;
}
public static SqlConnection opncon()
{
string connectionString = "Data Source=RAYYAN-THINK;Initial Catalog=newsProject;Integrated Security=True";
SqlConnection conn = new SqlConnection(connectionString);
return conn;
}
}
堆栈跟踪:
[XmlException: Root element is missing.]
System.Xml.XmlTextReaderImpl.Throw(Exception e) +69
System.Xml.XmlTextReaderImpl.ParseDocumentContent() +5589128
System.Xml.XmlTextReaderImpl.Read() +215
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +145
System.Xml.XmlDocument.Load(XmlReader reader) +107
System.Xml.XmlDocument.Load(Stream inStream) +130
poletics.ProcessRss(String rssUrl, String feed) in c:\Users\RAYYAN\Documents\Visual Studio 2012\WebSites\WebSite1\poletics.aspx.cs:57
poletics.Page_Load(Object sender, EventArgs e) in c:\Users\RAYYAN\Documents\Visual Studio 2012\WebSites\WebSite1\poletics.aspx.cs:36
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
最佳答案
错误解释了最常见的异常情况:您的 xml 中缺少根元素。
意思是,您很可能有多个“根”元素,因此这些元素不是根元素。您需要一个封装其他所有内容的 xml 元素。这是要检查的第一件事
关于c# - System.Xml.XmlException - 根元素丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19706778/
我在 Ubuntu 10.04 LTS 上运行 Eclipse Galileo。今天 Ubuntu 在我身上崩溃了,重新启动后,我发现 Eclipse 已经完全失去了 Java Perspective
我使用配置了 sonata_user 的 SonataAdminBundle在 config.yml : sonata_user: impersonating: route:
我有 ubuntu 14.04 但它不见了 docker exec sudo docker exec -it ubuntu_bash bash 我希望在现有正在运行的 docker 容器中运行交互式
我正在使用 Ubuntu 8.04/32 位(作为虚拟机)。在一个不是 min 的项目上执行一些 make 时,我得到了错误: g++:/usr/lib/libstdc++.a: 没有这样的文件或目录
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许在 Stack Overflow 上提出有关通用计算硬件和软件的问题。您可以编辑问题,使其成为
我正在尝试获取有关我在 UIImagePicker 中选择的视频的一些数据。 因此,当它进入 UIImagePicker 委托(delegate)方法(如下)时,我知道我需要使用信息字典中的 UIIm
我的网站最近被可能的黑客行为删除了。我上传了备份的文件夹和数据库,但现在我的 View 没有显示。其他一切都有效。我想不出有什么变化,只是上传了几天前的备份。 这些字段在 admin/build/vi
我执行以下操作来设置我的 session ,这是有效的,因为 echo 出现了。但是当我转到下一页或另一页时, session 不存在吗?我做错了什么? $session_start(); if ($
我试图在 BigQuery 中使用这段代码,显然是从 GA 中获取数据,但 _TABLE_SUFFIX 似乎有问题。错误显示“错误:无法识别的名称:_TABLE_SUFFIX at [12:3]”您能
输入:8(2 5 6 9 10 2 7 4)预期输出:(2 7 9 9 12 5 7 6)实际输出:(2 7 9 9) 这是我的大学作业,也是我第一次在这里提问。我不知道为什么,但 10 没有扫描,有
$('div'); // 我在上面的代码中遇到错误。在检查 .js 代码时,我找不到名为 $ 的函数,但根据文档,应该有一个。 最佳答案 试试 http://ajax.googleapis.co
以下简单代码的输出对我来说有点奇怪。它错过了在控制台上打印的 0 到 100 之间的一些数字。 谁能解释一下为什么省略打印?我对并发编程完全陌生。 import java.util.concurren
我正在学习 xamarin 以构建移动应用程序,但我对 Xamarin 和移动应用程序一无所知。我打开了一个空白的移动应用程序,其中有“Hello world”示例并编辑了一些文本,但我的应用程序图标
我正在将一些值存储到 sqlite 数据库中。因此,数据是作为字符串从文本字段收集的,然后转换为 double 并持久化。 这是我试过的 NSDecimalNumber 答案; value.answe
我有一个奇怪的案例。突然,其中一个表中的一些记录(这么多记录)丢失了。首先,我认为这是由我的 PHP 脚本中的错误引起的。但是,我检查了一下,我的脚本中没有DELETE操作,只有UPDATE。有谁知道
我正在复制 NSString来自 NSDictionary进入本地NSString使用 [[NSString alloc] initWithString:] ,对其进行处理(删除一些字符),然后将其发
当保存在根文件夹中时,我的非常基本的 html 页面保持样式。为一个组创建了一个新文件夹,但是当我将页面移动到该文件夹时,它们似乎失去了与 css 文件的连接。 认为问题可能出在链接上,因为它现在
我需要使用 OpenCV 训练一些图像。但问题是,我找不到 opencv_createsamples 程序。我以正常方式安装了 OpenCV,因为我使用的是 Windows 7。这个 opencv_c
我有一个绑定(bind)到 JTable 的 ArrayList。之后 bindingGroup.unbind(); bindingGroup.bind(); (完成刷新数据)我丢失了表格单元格渲
所以基本上我们只是丢失了一个 keystore 和备份 keystore 。但是我们可能知道原始 keystore 的密码。 我的问题是,如果我们知道原始 keystore 的密码,我们可以重新生成
我是一名优秀的程序员,十分优秀!