이전 질문이지만 대답이 필요합니다.
여기 은입니다. RSS 또는 Atom 피드가 있는지 확인하는 비교적 간단한 방법입니다. 그것은 독서, 또는 문서를 읽으려고합니다.
public SyndicationFeed GetSyndicationFeedData(string urlFeedLocation)
{
XmlReaderSettings settings = new XmlReaderSettings
{
IgnoreWhitespace = true,
CheckCharacters = true,
CloseInput = true,
IgnoreComments = true,
IgnoreProcessingInstructions = true,
//DtdProcessing = DtdProcessing.Prohibit // .NET 4.0 option
};
if (String.IsNullOrEmpty(urlFeedLocation))
return null;
using (XmlReader reader = XmlReader.Create(urlFeedLocation, settings))
{
if (reader.ReadState == ReadState.Initial)
reader.MoveToContent();
// now try reading...
Atom10FeedFormatter atom = new Atom10FeedFormatter();
// try to read it as an atom feed
if (atom.CanRead(reader))
{
atom.ReadFrom(reader);
return atom.Feed;
}
Rss20FeedFormatter rss = new Rss20FeedFormatter();
// try reading it as an rss feed
if (rss.CanRead(reader))
{
rss.ReadFrom(reader);
return rss.Feed;
}
// neither?
return null;
}
}
나는 다른 생각을 보았지만 나는 그것을 좋아하지 않는 이유를 기억하지 않는다. 그것은 너무 오래 전이었고,이 작품, 그래서 이것을 최고의 대답, 고맙습니다 :) – SelAromDotNet
그래, 내가이 피드를 시도 할 때 (http://en.espnf1.com/rss/motorsport/story/feeds/0.xml ? type = 2) atom.CanRead (reader) 행이 false를 반환하기 때문에 Atom 2.0 유형의 코드가 작동하지 않습니다. Atom Ver를 처리 할 수있는 해결책은 무엇입니까? 2.0? – Marko
아는 한 원자 2.0이 아닙니다. 그 피드가 깨진 것처럼 보입니다. 그것에는 쓰레기가 있습니다. 이 문제를 해결하려면 피드를 읽으 려하기 전에 피드를 수정하는 것이 좋습니다. 나는 이것을 시도하고 그것은 나를 위해 여기에서 일한다. – Cheeso