.net - Adding Namespaces to a SyndicationFeed rather than Individual Elements? -


i have class this:

public static class myfeedextensions {     private readonly static xnamespace _namespace = xnamespace.get(@"http://mynamespace");      public static xelement myelement(string value)     {         return new xelement(_namespace + "myelement", value);     } } 

i'm using generate atom feed custom extensions:

var feed = new syndicationfeed(); feed.elementextensions.add(myfeedextensions.myelement("testing!")); 

this works fine, except feed adds namespace element:

<feed xmlns="http://www.w3.org/2005/atom">   <title type="text">hello world!</title>   <id>00000000-0000-0000-0000-000000000000</id>   <updated>2011-03-01t01:00:53z</updated>   <myelement xmlns="http://mynamespace">testing!</myelement> </feed> 

is there way register namespace feed instead, output this?

<feed xmlns="http://www.w3.org/2005/atom" xmlns:my="http://mynamespace">   <title type="text">hello world!</title>   <id>00000000-0000-0000-0000-000000000000</id>   <updated>2011-03-01t01:00:53z</updated>   <my:myelement>testing!</my:myelement> </feed> 

ideally, work when have syndicationitems elementextensions, feed should know various namespaces.

(edit: purely reduce size of xml , make easier read humans)

found answer in this question , adapted it:

feed.attributeextensions.add(     new xmlqualifiedname("my",xnamespace.xmlns.tostring()),     myfeedextensions.namespace.tostring()); 

basically: register xmlns:my attribute feed, pick namespace automatically on elements if added syndicationitem within feed.

obscure, neat!


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -