在我的WPF應用程序中,我想編寫代碼來讀取Atom xaml Feed。有Web links
像www.myweblink/NewXaml.xaml
我希望我的代碼使用此鏈接,並從此鏈接中定義的此xaml文件中獲取標題和說明。如何讀取WPF中的Atom XAML文件?
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> . . . . . .
代碼改爲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;
}
}
錯誤:它產生的錯誤,那rss
在XAML filde是無效的。
問題1:如何從這個xaml文件獲得標題和描述?
問題2:我希望我的程序自動轉到此鏈接,而不是這個,我必須將此文件保存在我的PC上,併爲此代碼添加路徑以使其硬編碼。
誰能請幫助我。
你_sure_,這是一個有效的流程文檔_XAML_文件?看起來像一個Atom _XML_飼料給我。 – Gusdor
@Gusdor哦,是的。我很抱歉,我忘記提到這個:( - – user2835256
你應該修改你對XAML的引用。這裏沒有xaml文件。 – Gusdor