如何使用C#和.NET 4創建Atom條目?C原子條目#
我需要這個結構中的條目:
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:f="XXX:aaa">
<title>title1</title>
<summary>summary1</summary>
</entry>
我試着用SyndicationItem類來做到這一點,但條目中包含更多的信息比我更需要:
SyndicationItem atom = new SyndicationItem();
atom.Title = new TextSyndicationContent("test1", TextSyndicationContentKind.Plaintext);
atom.Summary = new TextSyndicationContent("summary1");
atom.AttributeExtensions.Add(new XmlQualifiedName("f", "http://www.w3.org/2000/xmlns/"), "XXX:aaa");
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineOnAttributes = true;
StringBuilder sb = new StringBuilder();
XmlWriter xml = XmlWriter.Create(sb,settings);
atom.SaveAsAtom10(xml);
xml.Close();
Console.WriteLine(sb.ToString());
,其結果是:
<entry xmlns:f="XXX:aaa" xmlns="http://www.w3.org/2005/Atom">
<id>uuid:34381971-9feb-4444-9e6a-3fbc412ac6d2;id=1</id>
<title type="text">title1</title>
<summary type="text">summary1</summary>
<updated>2010-10-29T14:02:48Z</updated>
</entry>
如何創建沒有的原子輸入對象,並使用type =「*」來使它看起來完全一樣想要什麼?
你能幫我簡化代碼嗎?
謝謝!
這正是我想要做的,我使用syndicationitem對象,但我不能讓它創建我想要的條目,但謝謝你的argotic我會嘗試。但是最好使用syndicationitem,因爲它已經在框架中。 – 2010-10-29 18:39:02
我誤解了你的問題,我的答案已更新。 – jgauffin 2010-10-29 19:21:32
謝謝你的幫助! – 2010-10-29 19:53:05