困惑中的Atom feed命名空间 [英] Confused about namespaces in Atom feed

查看:243
本文介绍了困惑中的Atom feed命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别

 < OpenSearch的:totalResults> 1000℃; / OpenSearch的:totalResults>
 

 < totalResults的xmlns =OpenSearch的> 1000℃; / totalResults>
 

我使用SyndicationFeed类在.NET中生成一个Atom feed,我需要添加一些元素的OpenSearch的标准,但它一直像后者添加元素时,我想它来增加他们像上述前者。

在code:

  feed.ElementExtensions.Add(totalResults,OpenSearch的,2);
 

修改

根饲料标签看起来像这样

 <饲料XML:LANG =EN-USP1:OpenSearch的=htt​​p://a9.com/-/spec/opensearch/1.1/的xmlns:P1 = 的xmlns的xmlns =htt​​p://www.w3.org/2005/Atom>
 

改变我的code作为@Reddog建议后,totalresults元素看起来像这样

 < totalResults的xmlns =htt​​p://a9.com/-/spec/opensearch/1.1/> 1000℃; / totalResults>
 

在code,增加了空间的饲料标签看起来像这样

  feed.AttributeExtensions.Add(
    新XmlQualifiedName(OpenSearch的,的xmlns),
    @http://a9.com/-/spec/opensearch/1.1/);
 

而code,现在增加了totalresults元素看起来像这样

  feed.ElementExtensions.Add(totalResults,@http://a9.com/-/spec/opensearch/1.1/,1000);
 

解决方案

没关系。我意识到,我被错误地添加的命名空间。它应该是

  feed.AttributeExtensions.Add(
   新XmlQualifiedName(OpenSearch的,http://www.w3.org/2000/xmlns/),
   http://a9.com/-/spec/opensearch/1.1/);
 

Is there any difference between

<opensearch:totalResults>1000</opensearch:totalResults>

and

<totalResults xmlns="opensearch">1000</totalResults>

I'm using the SyndicationFeed class in .NET to generate an Atom feed, and I need to add some elements for the opensearch standard, but it keeps adding elements like the latter one above when I want it to add them like the former one.

The code:

feed.ElementExtensions.Add("totalResults", "opensearch", "2");

EDIT

The root feed tag looks like this

<feed xml:lang="en-US" p1:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:p1="xmlns" xmlns="http://www.w3.org/2005/Atom">

After changing my code as @Reddog suggested, the totalresults element looks like this

<totalResults xmlns="http://a9.com/-/spec/opensearch/1.1/">1000</totalResults>

The code that adds the namespace to the feed tag looks like this

feed.AttributeExtensions.Add(
    new XmlQualifiedName("opensearch", "xmlns"),
    @"http://a9.com/-/spec/opensearch/1.1/");

And the code that adds the totalresults element now looks like this

feed.ElementExtensions.Add("totalResults", @"http://a9.com/-/spec/opensearch/1.1/", "1000");

解决方案

Nevermind. I realized that I was adding the namespace incorrectly. It should be

feed.AttributeExtensions.Add(
   new XmlQualifiedName("opensearch", "http://www.w3.org/2000/xmlns/"),
   "http://a9.com/-/spec/opensearch/1.1/");

这篇关于困惑中的Atom feed命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆