使用C#进行Atom入口

Ale*_*erg 5 .net c# syndication-item atompub atom-feed

如何使用C#和.NET 4创建Atom条目?

我需要使用这种结构创建一个条目:

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:f="XXX:aaa">
  <title>title1</title>
  <summary>summary1</summary>
</entry>
Run Code Online (Sandbox Code Playgroud)

我尝试使用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());
Run Code Online (Sandbox Code Playgroud)

结果是:

<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>
Run Code Online (Sandbox Code Playgroud)

如何在没有的情况下创建原子入口对象,并输入="*"以使其看起来完全是我想要的?

你能帮我简化代码吗?

谢谢!

jga*_*fin 1

为什么要自己做?

使用 .Net 中的内置功能:

或者 Argotic Syndicate 工具包:

编辑

抱歉,错过了您使用联合项目的部分。无论如何,这里是来自 ATOM 规范(RFC4287 第 4.1.2 节)的一些文本:

  • atom:entry 元素必须包含一个atom:id 元素
  • atom:entry 元素必须恰好包含一个atom:updated 元素

换句话说:如果删除这些项目,您就会违反标准。