Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 序列化元素仅因rel=”不同的XML;_C#_Xml_Xml Serialization - Fatal编程技术网

C# 序列化元素仅因rel=”不同的XML;

C# 序列化元素仅因rel=”不同的XML;,c#,xml,xml-serialization,C#,Xml,Xml Serialization,我正在尝试序列化一些XML。通常,我只会创建一个类并使用System.Xml.Serialization.XmlSerializer。然而,在这种情况下,会出现各种问题,例如一些链接标记,它们只是因为rel='而不同 因此,我不知道如何序列化它并为此创建类。有什么想法吗?下面是XML的一个示例: <?xml version="1.0" encoding="UTF-8"?> <feed xml:lang="en-US" xmlns:opensearch="http://a9.co

我正在尝试序列化一些XML。通常,我只会创建一个类并使用System.Xml.Serialization.XmlSerializer。然而,在这种情况下,会出现各种问题,例如一些链接标记,它们只是因为rel='而不同

因此,我不知道如何序列化它并为此创建类。有什么想法吗?下面是XML的一个示例:

<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:api.microsoft.com,2005:search/foo</id>
  <title>foo - microsoft Search</title>
  <link type="application/atom+xml" rel="next" href="http://api.microsoft.com/search?page=2&amp;q=foo" />
  <link type="application/atom+xml" rel="self" href="http://api.microsoft.com/search?page=1&amp;q=foo&amp;since_id=1286331268264" />
  <link type="application/atom+xml" rel="refresh" href="http://api.microsoft.com/search?q=foo&amp;since_id=1286331268264" />
  <link type="application/atom+xml" rel="after" href="http://api.microsoft.com/search?q=foo&amp;after_id=1286322320913" />
  <opensearch:totalResults>1173</opensearch:totalResults>
  <opensearch:itemsPerPage>20</opensearch:itemsPerPage>
  <updated>2010-10-06T02:14:28Z</updated>

  <entry xmlns="http://www.w3.org/2005/Atom">
    <title>Comment on Eating in New Mexico Day 1 & 2 by Tricia</title>
    <link href="http://zmommyt.wordpress.com/2007/08/28/eating-in-new-mexico-day-1-2/#comment-126" type="text/html" rel="alternate" />
    <published>2007-08-29T01:52:00Z</published>
    <id>http://zmommyt.wordpress.com/2007/08/28/eating-in-new-mexico-day-1-2/#comment-126</id>
    <updated>2007-08-29T01:52:00Z</updated>
    <language xmlns='http://api.microsoft.com/ns/search-0#results'>blog</language>
    <category xmlns='http://api.microsoft.com/ns/search-0#results'>blog</category>
    <abstract xmlns='http://api.microsoft.com/ns/search-0#results'>>
      <p>You&#8217;re making me hungry for green chile! I told my
      farmer last week that I was already missing it - unfortunately,
      his chiles won&#8217;t be ripe...  ...Sigh&#8230; I love
      that first picture! What great pictures.  Comment on Eating in
      New Mexico Day 1 & 2 by Tricia</p>
    </abstract>
  </entry>

  <entry xmlns="http://www.w3.org/2005/Atom">
    <title>Comment on Eating in New Mexico Day 1 & 2 by Tricia</title>
    <link href="http://zmommyt.wordpress.com/2007/08/28/eating-in-new-mexico-day-1-2/#comment-126" type="text/html" rel="alternate" />
    <published>2007-08-29T01:52:00Z</published>
    <id>http://zmommyt.wordpress.com/2007/08/28/eating-in-new-mexico-day-1-2/#comment-126</id>
    <updated>2007-08-29T01:52:00Z</updated>
    <language xmlns='http://api.microsoft.com/ns/search-0#results'>blog</language>
    <category xmlns='http://api.microsoft.com/ns/search-0#results'>blog</category>
    <abstract xmlns='http://api.microsoft.com/ns/search-0#results'>>
      <p>You&#8217;re making me hungry for green chile! I told my
      farmer last week that I was already missing it - unfortunately,
      his chiles won&#8217;t be ripe...  ...Sigh&#8230; I love
      that first picture! What great pictures.  Comment on Eating in
      New Mexico Day 1 & 2 by Tricia</p>
    </abstract>
  </entry>
</feed>

标签:api.microsoft.com,2005:search/foo
foo-微软搜索
1173
20
2010-10-06T02:14:28Z
Tricia对新墨西哥州第1天和第2天饮食的评论
2007-08-29T01:52:00Z
http://zmommyt.wordpress.com/2007/08/28/eating-in-new-mexico-day-1-2/#comment-126
2007-08-29T01:52:00Z
博客
博客
>
你’;你让我渴望绿色智利!我告诉我的朋友
farmer上周说我已经错过了很不幸,
他的智利元’;我还没熟。。。叹息…;我爱
第一张照片!多好的照片啊。关于在家吃饭的评论
新墨西哥州第一和第二天特里西亚

Tricia对新墨西哥州第1天和第2天饮食的评论 2007-08-29T01:52:00Z http://zmommyt.wordpress.com/2007/08/28/eating-in-new-mexico-day-1-2/#comment-126 2007-08-29T01:52:00Z 博客 博客 > 你’;你让我渴望绿色智利!我告诉我的朋友 farmer上周说我已经错过了很不幸, 他的智利元’;我还没熟。。。叹息…;我爱 第一张照片!多好的照片啊。关于在家吃饭的评论 新墨西哥州第一和第二天特里西亚

如果将应用于链接集合属性,则XmlSerializer会将它们反序列化为有序集合

[XmlRoot(Namespace = "http://www.w3.org/2005/Atom")]
public class feed
{
    [XmlElement("link")]
    public link[] link { get; set; }
}

public class link
{
    [XmlAttribute]
    public string type { get; set; }

    [XmlAttribute]
    public string rel { get; set; }

    [XmlAttribute]
    public string href { get; set; }
}