如何读取一个Atom XAML文件在WPF? [英] How to read an Atom XAML File in WPF?
问题描述
在我的WPF应用程序,我想写code阅读的Atom XAML饲料。有网站链接
如 www.myweblink / NewXaml.xaml
我想有我的code使用这个链接并获得标题和描述的在这个环节中定义此XAML文件。
In my WPF Application i want to write code to read Atom xaml Feed. There are Web links
like www.myweblink/NewXaml.xaml
I want that there my code use this link and get title and description from this xaml file defined in this link.
ATOM XAML.FILE
<?xml version='1.0' encoding='UTF-8' ?>
<rss version='2.0' xmlns:atom='http://www.w7.org7/Atom'>
<channelWay>
<title>Text1 - Network</title>
<atom:link href='http://link1/myxaml.xml' rel='self' type='typeOne/rss+xml' />
<link>http://website.com</link>
<description> This is New Description </description>
<lastBuildDate>Fri, 2 Oct 2011 00:00:00 +0500</lastBuildDate>
<language>en-us</language>
<item>
<title>
My First Title
</title>
<link>http://website.com/PageOne.aspx?ID=123790</link>
<guid>http://website.com/PageTwo.aspx?ID=123790</guid>
<description>
My First Description
</description>
<pubDate>Fri, 2 Oct 2011 13:10:00 +0500</pubDate>
</item>
<item>
<title>
My Second Title
</title>
<link>
<link>http://website.com/PageOne1.aspx?ID=123790</link>
<guid>http://website.com/PageTwo1.aspx?ID=123790</guid>
<description>
My Second Description
</description>
<pubDate>Fri, 2 Oct 2011 13:10:00 +0500</pubDate>
</item> . . . . . .
code要读取XAML文件:
public Window1()
{
InitializeComponent();
FlowDocument content = null;
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "FlowDocument Files (*.xaml)|*.xaml|All Files (*.*)|*.*";
if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
FileStream xamlFile = openFile.OpenFile() as FileStream;
if (xamlFile == null) return;
else
{
try
{
content = XamlReader.Load(xamlFile) as FlowDocument;
if (content == null)
throw(new XamlParseException("The specified file could not be loaded as a FlowDocument."));
}
catch (XamlParseException e)
{
String error = "There was a problem parsing the specified file:\n\n";
error += openFile.FileName;
error += "\n\nException details:\n\n";
error += e.Message;
System.Windows.MessageBox.Show(error);
return;
}
catch (Exception e)
{
String error = "There was a problem loading the specified file:\n\n";
error += openFile.FileName;
error += "\n\nException details:\n\n";
error += e.Message;
System.Windows.MessageBox.Show(error);
return;
}
FlowDocRdr.Document = content;
}
}
错误:它会产生错误的新闻
在XAML filde是无效的。
Error: It Generates Error that rss
in Xaml filde is invalid.
Q1:我怎样才能获得标题和描述从这个XAML文件
Q1: How Can i get title and description from this xaml file?
Q2:我想我的计划去这个链接将自动代替这一点,我要保存此文件在我的电脑,并给它的路径,这code,使其很难codeD
Q2: I want my program to go to this link automatically instead of this that i have to save this file on my PC and to give it's path to this code to make it hard coded.
任何人都可以请帮助我。
Can anyone please help me.
推荐答案
@Gusdor是正确的,我想太多,你说的是的Atom XML提要
。
下面是详细的文章与 XML提要
第一条,
第二条
@Gusdor is right, i think too that you are talking about Atom XML Feed
.
Here are detailed article related to XML Feed
Article1,
Article2
请阅读这些文章。这是真正的帮助,了解基础知识 RSS
和 SyndicationFeed
。
Please read these articles. These are really helpful to understand basics of RSS
and SyndicationFeed
.
下面code是:
XmlReader reader = XmlReader.Create(@"http://link1/myxaml.xml");
SyndicationFeed feed = SyndicationFeed.Load(reader);
var titles = from item in feed.Items
select new
{
item.Title.Text,
};
var descriptions = from item in feed.Items
select new
{
item.Summary.Text
};
foreach (var t in titles)
{
title_textbox.Text += t.Text + " "; //Your All Titles Here
}
foreach (var des in descriptions)
{
description_textbox.Text += des.Text + " "; //Your All Descriptions Here
}
这篇关于如何读取一个Atom XAML文件在WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!