当前位置:编程学习 > C#/ASP.NET >>

如何生成Atom格式的XML文件,并且输出出来

求教啊,有没有做过的,直接把对象或datatable行生成如下的xml,是atom格式的
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title />
  <updated>2008-09-18T23:46:19.3857256Z<updated/>
  <author>
    <name />
  </author>
  <id />
  <content type="application/xml">
    <m:properties>
      <d:Address>Mountain View</d:Address>
      <d:Age m:type="Edm.Int32">23</d:Age>
      <d:AmountDue m:type="Edm.Double">200.23</d:AmountDue>
      <d:BinaryData m:type="Edm.Binary" m:null="true" />
      <d:CustomerCode m:type="Edm.Guid">c9da6455-213d-42c9-9a79-3e9149a57833</d:CustomerCode>
      <d:CustomerSince m:type="Edm.DateTime">2008-07-10T00:00:00</d:CustomerSince>
    </m:properties>
  </content>
</entry>
</feed>



现在生成的是这样,coutent 中的不一样,求帮助,急急急急急
<?xml version="1.0" encoding="utf-16"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Test Feed</title>
  <subtitle type="text">This is a test feed</subtitle>
  <id>TestFeedID</id>
  <updated>2013-03-27T11:00:31+08:00</updated>
  <link rel="alternate" href="http://contoso/testfeed" />
  <entry>
    <id>TestItemID</id>
    <title type="text">Test Item</title>
    <updated>2013-03-27T11:00:31+08:00</updated>
    <link rel="alternate" href="http://localhost/ItemOne" />
    <content type="name">
      <ceshi xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DailyWorkWeb.QueryService">
        <ProjectId>4oC官网2013</ProjectId>
        <WorkLoadId>2</WorkLoadId>
      </ceshi>
    </content>
  </entry>
</feed>


代码如下
Response.Charset = "UTF-8";
            DailyWorkLoad dailyWorkLoad = new DailyWorkLoad(2);

            SyndicationFeed feed = new SyndicationFeed("Test Feed", "This is a test feed", new Uri("http://Contoso/testfeed"), "TestFeedID", DateTime.Now);
            SyndicationItem item = new SyndicationItem("Test Item", "This is the content for Test Item", new Uri("http://localhost/ItemOne"), "TestItemID", DateTime.Now);
            item.Content = new XmlSyndicationContent("name", dailyWorkLoad, new System.Xml.Serialization.XmlSerializer(typeof(DailyWorkLoad)));
            List<SyndicationItem> items = new List<SyndicationItem>();
            items.Add(item);
            feed.Items = items;
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
            xmlWriterSettings.Encoding = System.Text.Encoding.GetEncoding("utf-8");
            XmlWriter atomWriter = XmlWriter.Create(stringBuilder, xmlWriterSettings);
            Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed);
            
            atomFormatter.WriteTo(atomWriter);
            atomWriter.Close();
            Response.Clear();
            Response.Write(stringBuilder.ToString()); xml --------------------编程问答-------------------- 无非是自己多拼一下字符串,又不是很麻烦的事情。 --------------------编程问答-------------------- 我在帮助文档中看到XmlSyndicationContent生成之后的格式一个就是 --------------------编程问答-------------------- 我在帮助文档中看到 --------------------编程问答-------------------- 我在帮助文档中看到XmlSyndicationContent生成的格式就是如下的,不知道怎么不行,有没有做个这个的,求教
<content type="MyXMLType">
    <mg:MyElement xmlns:mg="http://migree/elements">This is some text</mg:MyElement>
</content> --------------------编程问答-------------------- 可以使用WCF Data Services for OData 
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,