2013-05-28 6 views
0

사용자 정의 RSS 요소 som 맞춤 요소로 맞춤 rss 피드를 설정 중입니다. 사용자 지정 특성이있는 사용자 지정 요소를 추가해야합니다.맞춤 속성 C#

지금까지 나는이 같은 피드를 설정 한 :

var testItem = new SyndicationItem("title", "description", new Uri("http://myuri.com")); 

customItem.ElementExtensions.Add("customElement", String.Empty, "fooBar"); 

는 "항목"라는 이름의 목록에 testItem를 추가하고 :

var feed = new SyndicationFeed("TestFeed", "FeedContent", new Uri("http://myuri.com"), items); 

이 이런 식으로 뭔가를 생산하는 것입니다 ..

<rss> 
    <channel> 
    <title>TestFeed</title> 
    <link>http://myuri.com</link> 
    <description>FeedContent</description> 
    <item> 
     <link>http://myprovider.com/contentid=1234</link> 
     <title>title</title> 
     <description>description</description> 
     <customElement>fooBar</customElement> 
    </item> 
    </channel> 
</rss> 

사용자 지정 요소를 추가 한 다음이 요소에 사용자 지정 특성을 추가하려면 어떻게해야합니까?

var customElement = new SyndicationItem(); 

을 그리고 이런 식으로 속성을 추가 :

나는이 같은 새 SyndicationItem 형을 만들 수 있습니다

customElement.AttributeExtensions.Add(new XmlQualifiedName("myAttribute", ""), "someValue"); 
customElement.AttributeExtensions.Add(new XmlQualifiedName("anotherAttribute"), "someOtherValue"); 

을 그리고 내 목록에 그것을 가지고 내 testItem에 추가 RSS 피드의 항목 :

컴파일러가 먹지만 런타임 오류가 발생합니다. 새로운 요소에는 이름이 없습니다.

내가이 일을 다른 방법을 찾을 수 없습니다,

다음 피드의 해당 xmldoc를 만들고 외에 그것에 요소와 attibutes를 추가 시작합니다.

그냥 그렇게해야 할 것이 이상한 것, 그리고 내가 뭔가 ..

어떤 아이디어를 감독해야합니다 느낌?

답변

2

해결책을 찾았습니다.

var contentItem = new SyndicationItem("title", "description", new Uri("http://myuri.com")); 

을 다음과 같이이 사용자 정의 요소를 추가 :

나는이 같은 피드에 항목을 추가 할 수 있습니다 나는 정의 요소를 추가하고 사용자 정의를 추가하려면

contentItem.ElementExtensions.Add("customElement", String.Empty, "text inside my custom element"); 

그것에 대한 속성; 내가 할 수있는 :

contentItem.ElementExtensions.Add(new XElement("customImageElement", new XAttribute("type", "image/jpg"), new XAttribute("url", "www.myuri.com/pic1234.jpg")).CreateReader()); 

이는 것 출력 :

<customImageElement type="image/jpg" url="www.myprovider.com/pic1234.jpg"></customImageElement> 

내가 끝났어요 때, 나는 List<SyndicationItem>에의 ContentItem을 추가하고, 내가 피드 (항목)를 만들 때이 목록을 추가 할 수 있습니다.

나는 또한 <channel> 요소 아래에, 공급 자체에 사용자 지정 요소를 추가 할 수 있습니다

첫 번째 항목의 목록이 피드를 추가

var feed = new SyndicationFeed("title text", "description text", new Uri("http://myuri.com"), items); 

그런 다음 피드에 사용자 지정 요소를 추가합니다. 요소 미만 :

feed.ElementExtensions.Add(new XElement("image", 
      new XElement("url", null, "http://www.myuri.com/logo.jpg"), 
      new XElement("title", null, "MyImage"), 
      new XElement("link", null, "http://myuri.com/contentid=1234"), 
      new XElement("width", null, "100"), 
      new XElement("height", null, "100"), 
      new XElement("description", null, "This is my image")).CreateReader()); 

이는 것 출력 : 내가 가지고 올 수있는 무엇

<rss version="2.0"> 
<channel> 
    <title>title text</title> 
    <link>http://myuri.com</link> 
    <description>description text</description> 
    <image> 
     <url>http://www.myprovider.com/logo.jpg</url> 
     <title>MyImage</title> 
     <link>http://myprovider.com/contentid=1234</link> 
     <width>100</width> 
     <height>100</height> 
     <description>This is my image</description> 
    </image> 
    <item> 
     Items added to the items collection 
     ... 
     ... 
     ... 
    </item> 
    </channel> 
</rss> 

. 더 좋은 방법이 있다면 공유하십시오.

+0

나는 내일까지 내 자신의 대답을 받아 들일 수 없으므로 저를 위해 파운드하지 마십시오 :-) – Soeren

+0

어떤 종류의 자바 스크립트 RSS 리더가 사용자 정의 rss 버전 2.0 피드를 읽을 수 있습니까? 그것에있는 요소들? 이 페이지 (http://www.w3schools.com/rss/rss_item.asp)를 읽은 후 사용자 정의 요소를 블록에 추가하는 방법이나이를 읽는 방법에 대한 언급이 없습니다. 사용자 정의 피드를 읽는 독자에 대한 조언을 주셔서 감사합니다. – blackhawk

+1

나는이 아이디어를 읽으려면 코드가 필요하다고 생각하지만 나머지 RSS 피드는 여전히 표준 RSS 뷰어에서 볼 수 있습니다. 그것은 우리가 어쨌든하고있는 것입니다. –