2010-10-24 19 views
6

Sono un po 'nuovo ai feed RSS, ma sono in grado di creare un feed in modo dinamico usando PHP e funziona alla grande. Il mio problema è che a volte il feed non ha articoli (limito l'età degli articoli per i feed a 60 giorni, e talvolta non è successo nulla in quel momento).Come creare un feed RSS "vuoto"

Quello che mi aspetto di accadere è che semplicemente non avrei alcun <item> s nella mia pagina xml. Tuttavia, quando lo faccio in questo modo, il lettore di feed (almeno quello di Google) sembra essere un po 'borked. Anche se l'XML contiene il nome del feed correttamente, esso appare senza un titolo.

L'unico modo che ho trovato finora per risolvere questo problema è inserire un elemento fittizio, che è semplicemente <item><title></title></item>. Quindi il mio lettore di Google trova correttamente il nome del feed e sembra proprio un feed vuoto.

Sembra che sia una soluzione hokey probabilmente non corretta.

Esiste un modo standard per gestire la presentazione XML per un feed vuoto?

Edit: Ecco ciò che il mangime vuoto sembra

<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 
xmlns:admin="http://webns.net/mvcb/" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:content="http://purl.org/rss/1.0/modules/content/"> 

<channel> 

<title>News at Example</title> 

<link>http://www.example.com/feed/sample-reviews</link> 
<description>Latest Additions to the Sample Category</description> 
<dc:language>en-us</dc:language> 
<dc:creator>Contact Example through our "contact us" page</dc:creator> 

<dc:rights>Copyright 2010 Example Technologies Inc.</dc:rights> 
<admin:generatorAgent rdf:resource="http://www.codeigniter.com/" /> 

     <item><title></title></item> 

</channel></rss> 
+2

Sembra un bug. Non c'è nulla in linea di principio sbagliato con un '' meno feed. – bobince

+0

Puoi mostrare un esempio completo del tuo feed? –

+0

L'ho aggiunto. Senza quel tag vuoto , Google Reader non raccoglie il titolo principale del feed per qualche motivo. Con esso in là, funziona bene. E funziona bene anche con oggetti reali. Proprio quando non c'è nessun elemento sto avendo un problema. – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/478053/">neomech</a></span> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="answer-title"> <span class="text-logo margin-top-sm">A</span> <h2 class="title h4">risposta</h2> </div> <div class="item-description text-md markdown-body margin-bottom-40 voidso"> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">5<i class="fa fa-thumbs-up"></i></span> <i class="fa fa-check fa-2x"></i> </div> <div class="post-offset"> <div class="answer fmt"> <p>Un feed è vuoto un involucro di alimentazione (la roba XML in generale) senza alcun elemento. Il contenitore deve essere ancora valido perché sia ​​un feed valido.</p> <p>Da <a href="http://cyber.law.harvard.edu/rss/rss.html#hrelementsOfLtitemgt" rel="nofollow noreferrer">RSS 2.0 Specification</a>, mentre a partire dal 2003:</p> <blockquote> <blockquote> <p>Un canale può contenere qualsiasi numero di < item> s</p> </blockquote> </blockquote> <p>Tuttavia, da almeno <a href="http://www.thearchitect.co.uk/schemas/rss-2_0.xsd" rel="nofollow noreferrer">one RSS XSD</a> possiamo vedere che non è onorato e gli sviluppatori lo sanno:</p> <pre> <xs:element name="item" type="RssItem" minOccurs="1" maxOccurs="unbounded"> <!-- HACK: According to the RSS 2.0 spec, it should strictly be possible to have zero item elements, but this makes the schema non-deterministic with regard to extensibility elements so for the moment we undid bug-fix 10231 and set minOccurs=1 to work around this problem. --> </xs:element> </pre> <p>Prova il tuo feed in diversi client. Forse è solo un capriccio dell'implementazione di Google. YMMV.</p> <p>Felice codifica.</p> <p><strong>Modifica:</strong> Per il gusto di farlo, vedere la domanda SO: <a href="https://stackoverflow.com/questions/1650290/where-i-can-find-the-official-xsd-schema-for-rss-2-0">Where I can find the official XSD schema for RSS 2.0?</a>. È piuttosto deludente, in realtà: -/</p> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/4009145">fonte</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2010-10-24 16:31:26</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> <!-- comments --> <div class="comments"> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">Ho visto alcune discussioni online sull'impostazione di una sorta di elemento "predefinito" che indica che al momento non ci sono elementi di feed. Ha senso impostare un oggetto come quello dato il problema di non averne? – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/478053/">neomech</a></span> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">@neomech Usa qualunque cosa [migliore] per il/i cliente/i dato/i. Buona programmazione. – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> <div> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="4319274062" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">10<i class="fa fa-thumbs-up"></i></span> </div> <div class="post-offset"> <div class="answer fmt"> <p>Un feed con voci zero è perfettamente valido. Se Google Reader non lo gestisce correttamente, dovrebbe essere segnalato a loro come un bug e dovrebbero risolverlo.</p> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/4009177">fonte</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2010-10-24 16:36:19</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> <!-- comments --> <div class="comments"> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">Sono d'accordo. Detto questo, molte persone usano Google Reader (incluso me stesso!) E mi piacerebbe che il mio codice funzionasse correttamente nel frattempo, quindi tutti gli utenti che ho che utilizzano Google vedono almeno quello che dovrebbero. Sembra che avere una sorta di "trucco" per un feed vuoto sia la strada da percorrere. – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/478053/">neomech</a></span> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="clearfix"> </div> <div class="relative-box"> <div class="relative">Problemi correlati</div> <ul class="relative_list"> <li> 1. <a href="http://it.voidcc.com/question/p-kdbndrlu-o.html" target="_blank" title="Come autenticare un feed RSS"> Come autenticare un feed RSS </a> </li> <li> 2. <a href="http://it.voidcc.com/question/p-rkxmudlu-bs.html" target="_blank" title="Feed Parsing Feed RSS/Atom"> Feed Parsing Feed RSS/Atom </a> </li> <li> 3. <a href="http://it.voidcc.com/question/p-swjjfsql-a.html" target="_blank" title="Come posso creare un feed RSS/Atom in Rails 3?"> Come posso creare un feed RSS/Atom in Rails 3? </a> </li> <li> 4. <a href="http://it.voidcc.com/question/p-czykywxe-bs.html" target="_blank" title="Creare feed RSS in MVC4/WebAPI"> Creare feed RSS in MVC4/WebAPI </a> </li> <li> 5. <a href="http://it.voidcc.com/question/p-roikqess-o.html" target="_blank" title="Iscriviti a un feed RSS"> Iscriviti a un feed RSS </a> </li> <li> 6. <a href="http://it.voidcc.com/question/p-nzgkugcn-d.html" target="_blank" title="Feed RSS in PHP"> Feed RSS in PHP </a> </li> <li> 7. <a href="http://it.voidcc.com/question/p-rvgyvwkv-o.html" target="_blank" title="Linq al feed RSS?"> Linq al feed RSS? </a> </li> <li> 8. <a href="http://it.voidcc.com/question/p-avpekdyi-h.html" target="_blank" title="Tempo ritardare un RSS Feed esterna"> Tempo ritardare un RSS Feed esterna </a> </li> <li> 9. <a href="http://it.voidcc.com/question/p-ptpvplfy-a.html" target="_blank" title="deserializzazione un feed RSS in .NET"> deserializzazione un feed RSS in .NET </a> </li> <li> 10. <a href="http://it.voidcc.com/question/p-mrdqqloo-bx.html" target="_blank" title="Impostazione di un Github Commit Feed RSS"> Impostazione di un Github Commit Feed RSS </a> </li> <li> 11. <a href="http://it.voidcc.com/question/p-obwgcrwe-u.html" target="_blank" title="Come si costruisce un feed RSS con Jade?"> Come si costruisce un feed RSS con Jade? </a> </li> <li> 12. <a href="http://it.voidcc.com/question/p-hfsxgezk-c.html" target="_blank" title="Impaginazione in feed come ATOM e RSS?"> Impaginazione in feed come ATOM e RSS? </a> </li> <li> 13. <a href="http://it.voidcc.com/question/p-ayzbxhzt-s.html" target="_blank" title="Come disabilitare i feed RSS in STS?"> Come disabilitare i feed RSS in STS? </a> </li> <li> 14. <a href="http://it.voidcc.com/question/p-zyakuxaw-br.html" target="_blank" title="Come posso inserire questo feed RSS in un listview jQuery?"> Come posso inserire questo feed RSS in un listview jQuery? </a> </li> <li> 15. <a href="http://it.voidcc.com/question/p-utdaanol-bz.html" target="_blank" title="Come leggere tutti gli articoli da un feed RSS?"> Come leggere tutti gli articoli da un feed RSS? </a> </li> <li> 16. <a href="http://it.voidcc.com/question/p-rmimhctk-k.html" target="_blank" title="Come determinare a livello di codice se un feed RSS è un feed completo o un feed parziale"> Come determinare a livello di codice se un feed RSS è un feed completo o un feed parziale </a> </li> <li> 17. <a href="http://it.voidcc.com/question/p-fioncxtn-d.html" target="_blank" title="DateTime.Parse per pubDate nei feed RSS"> DateTime.Parse per pubDate nei feed RSS </a> </li> <li> 18. <a href="http://it.voidcc.com/question/p-nacjfybu-a.html" target="_blank" title="implementazione della sicurezza per i feed RSS"> implementazione della sicurezza per i feed RSS </a> </li> <li> 19. <a href="http://it.voidcc.com/question/p-xqmcsjdw-bp.html" target="_blank" title="Messaggi della pagina di Facebook feed rss?"> Messaggi della pagina di Facebook feed rss? </a> </li> <li> 20. <a href="http://it.voidcc.com/question/p-ffbnslld-bm.html" target="_blank" title="Feed RSS per recensioni di Apple App"> Feed RSS per recensioni di Apple App </a> </li> <li> 21. <a href="http://it.voidcc.com/question/p-rgrkorrk-cb.html" target="_blank" title="Il feed RSS non funziona su Chrome"> Il feed RSS non funziona su Chrome </a> </li> <li> 22. <a href="http://it.voidcc.com/question/p-gvxzzqie-br.html" target="_blank" title="Verifica URL del feed RSS valido"> Verifica URL del feed RSS valido </a> </li> <li> 23. <a href="http://it.voidcc.com/question/p-aquthhyn-o.html" target="_blank" title="notifica push per il feed RSS?"> notifica push per il feed RSS? </a> </li> <li> 24. <a href="http://it.voidcc.com/question/p-xfsjrgoj-c.html" target="_blank" title="ottieni il feed RSS nell'array php - possibile?"> ottieni il feed RSS nell'array php - possibile? </a> </li> <li> 25. <a href="http://it.voidcc.com/question/p-fosdcsag-d.html" target="_blank" title="Generatore di feed RSS decente per PHP"> Generatore di feed RSS decente per PHP </a> </li> <li> 26. <a href="http://it.voidcc.com/question/p-ybzixxke-cc.html" target="_blank" title="Feed RSS Reddit, oltre i 25 risultati?"> Feed RSS Reddit, oltre i 25 risultati? </a> </li> <li> 27. <a href="http://it.voidcc.com/question/p-kkicsmmq-bs.html" target="_blank" title="Feed RSS per il formato Apple News"> Feed RSS per il formato Apple News </a> </li> <li> 28. <a href="http://it.voidcc.com/question/p-gpkthtwu-bo.html" target="_blank" title="È ancora possibile creare un feed RSS da un gruppo Facebook?"> È ancora possibile creare un feed RSS da un gruppo Facebook? </a> </li> <li> 29. <a href="http://it.voidcc.com/question/p-btygnlwf-bu.html" target="_blank" title="RSS-Feed restituisce una stringa vuota"> RSS-Feed restituisce una stringa vuota </a> </li> <li> 30. <a href="http://it.voidcc.com/question/p-oxczkpje-x.html" target="_blank" title="Parse feed RSS tramite pacchetto XML R"> Parse feed RSS tramite pacchetto XML R </a> </li> </ul> </div> <div> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="3534119089"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img2.voidcc.com/voidso/script/side.js?t=1652515422436"></script> <script type="text/javascript" src="http://img2.voidcc.com/voidso/plugin/highlight/highlight.pack.js"></script> <link href="http://img2.voidcc.com/voidso/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- VOIDCC问答侧边栏广告 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="3862022848" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="row sidebar panel panel-default"> <div class="panel-heading font-bold"> Ultima domanda </div> <div class="m-b-sm m-t-sm clearfix"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://it.voidcc.com/question/p-eqfriish-bz.html" target="_blank" title="Firebase Cloud Messaging - Come convalidare i token?"> Firebase Cloud Messaging - Come convalidare i token? </a> </li> <li class="side_article_list_item"> 2. <a href="http://it.voidcc.com/question/p-xqcbnuus-bs.html" target="_blank" title="Differenza tra upload() e putObject() per caricare un file su S3?"> Differenza tra upload() e putObject() per caricare un file su S3? </a> </li> <li class="side_article_list_item"> 3. <a href="http://it.voidcc.com/question/p-dvazdehs-be.html" target="_blank" title="Googlesheet APIv4 ottiene celle vuote"> Googlesheet APIv4 ottiene celle vuote </a> </li> <li class="side_article_list_item"> 4. <a href="http://it.voidcc.com/question/p-wzdsjeoo-z.html" target="_blank" title="java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset() Ljava/nio/charset/Charset"> java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset() Ljava/nio/charset/Charset </a> </li> <li class="side_article_list_item"> 5. <a href="http://it.voidcc.com/question/p-njxikyzx-v.html" target="_blank" title="Differenza tra decimal.Round e Math.Round"> Differenza tra decimal.Round e Math.Round </a> </li> <li class="side_article_list_item"> 6. <a href="http://it.voidcc.com/question/p-rxnfwahb-bq.html" target="_blank" title="Come disabilitare un test usando py.test?"> Come disabilitare un test usando py.test? </a> </li> <li class="side_article_list_item"> 7. <a href="http://it.voidcc.com/question/p-yitoodyf-bd.html" target="_blank" title="Puoi usare un'espressione regolare in .babelrc?"> Puoi usare un'espressione regolare in .babelrc? </a> </li> <li class="side_article_list_item"> 8. <a href="http://it.voidcc.com/question/p-wvjzhcvh-bb.html" target="_blank" title="Connessione all'istanza di SQL Server locale quando si esegue il cluster di Service Fabric nell'ambiente di sviluppo"> Connessione all'istanza di SQL Server locale quando si esegue il cluster di Service Fabric nell'ambiente di sviluppo </a> </li> <li class="side_article_list_item"> 9. <a href="http://it.voidcc.com/question/p-wvgnetws-s.html" target="_blank" title="Come posso aggiungere una lunghezza predefinita all'audio registrato da MediaRecorder in Chrome?"> Come posso aggiungere una lunghezza predefinita all'audio registrato da MediaRecorder in Chrome? </a> </li> <li class="side_article_list_item"> 10. <a href="http://it.voidcc.com/question/p-bzeduzvg-bo.html" target="_blank" title="Come ottenere il valore del testo di input al momento del clic in ReactJS"> Come ottenere il valore del testo di input al momento del clic in ReactJS </a> </li> </ul> </div> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> Problemi correlati</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://it.voidcc.com/question/p-kdbndrlu-o.html" target="_blank" title="Come autenticare un feed RSS"> Come autenticare un feed RSS </a> </li> <li class="side_article_list_item"> 2. <a href="http://it.voidcc.com/question/p-rkxmudlu-bs.html" target="_blank" title="Feed Parsing Feed RSS/Atom"> Feed Parsing Feed RSS/Atom </a> </li> <li class="side_article_list_item"> 3. <a href="http://it.voidcc.com/question/p-swjjfsql-a.html" target="_blank" title="Come posso creare un feed RSS/Atom in Rails 3?"> Come posso creare un feed RSS/Atom in Rails 3? </a> </li> <li class="side_article_list_item"> 4. <a href="http://it.voidcc.com/question/p-czykywxe-bs.html" target="_blank" title="Creare feed RSS in MVC4/WebAPI"> Creare feed RSS in MVC4/WebAPI </a> </li> <li class="side_article_list_item"> 5. <a href="http://it.voidcc.com/question/p-roikqess-o.html" target="_blank" title="Iscriviti a un feed RSS"> Iscriviti a un feed RSS </a> </li> <li class="side_article_list_item"> 6. <a href="http://it.voidcc.com/question/p-nzgkugcn-d.html" target="_blank" title="Feed RSS in PHP"> Feed RSS in PHP </a> </li> <li class="side_article_list_item"> 7. <a href="http://it.voidcc.com/question/p-rvgyvwkv-o.html" target="_blank" title="Linq al feed RSS?"> Linq al feed RSS? </a> </li> <li class="side_article_list_item"> 8. <a href="http://it.voidcc.com/question/p-avpekdyi-h.html" target="_blank" title="Tempo ritardare un RSS Feed esterna"> Tempo ritardare un RSS Feed esterna </a> </li> <li class="side_article_list_item"> 9. <a href="http://it.voidcc.com/question/p-ptpvplfy-a.html" target="_blank" title="deserializzazione un feed RSS in .NET"> deserializzazione un feed RSS in .NET </a> </li> <li class="side_article_list_item"> 10. <a href="http://it.voidcc.com/question/p-mrdqqloo-bx.html" target="_blank" title="Impostazione di un Github Commit Feed RSS"> Impostazione di un Github Commit Feed RSS </a> </li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://it.voidcc.com/contact">Contattaci</a></li> <li>© 2020 IT.VOIDCC.COM</li> <li><a rel="nofollow" href="https://beian.miit.gov.cn/" target="_blank">沪ICP备13005482号-13</a></li> <li><script type="text/javascript" src="https://s9.cnzz.com/z_stat.php?id=1280098168&web_id=1280098168"></script></li> <li><a href="http://cn.voidcc.com/" target="_blank" title="程序问答园区">简体中文</a></li> <li><a href="http://hk.voidcc.com/" target="_blank" title="程序問答園區">繁體中文</a></li> <li><a href="http://ru.voidcc.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.voidcc.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.voidcc.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.voidcc.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.voidcc.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.voidcc.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.voidcc.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.voidcc.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.voidcc.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.voidcc.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.voidcc.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-77509369-5"></script> <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'UA-77509369-5'); </script> <script> var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?67d4731349f0b00136755b80364ce381"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>