RSS-Parser icon indicating copy to clipboard operation
RSS-Parser copied to clipboard

Getting RssParsingException for https://inc42.com/buzz/feed/

Open mayank12gt opened this issue 1 year ago • 0 comments

Describe the bug Code:

fun getFeed(): MutableLiveData<MyResponse<RssChannel>> {
        val parser = RssParser()
        viewModelScope.launch {
            feedData.postValue(MyResponse.loading())
            try {
             
                val rssChannel = parser.getRssChannel("https://inc42.com/buzz/feed/")
                feedData.postValue(MyResponse.success(rssChannel))
            }
            catch (exception:Exception){
                Log.d("err",exception.localizedMessage)
                Log.d("err",exception.stackTraceToString())
                feedData.postValue(MyResponse.error(exception.localizedMessage))
            }
        }
        return feedData
    }

Exception:

RssParsingException(message=Something went wrong during the parsing of the feed. Please check if the XML is valid, cause=org.xmlpull.v1.XmlPullParserException: Unexpected token (position:unknown @2:1 in java.io.InputStreamReader@3ecb104) )
                                                                                                    	at com.prof18.rssparser.internal.AndroidXmlParser$parseXML$2.invokeSuspend(AndroidXmlParser.kt:67)
                                                                                                    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
                                                                                                    	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
                                                                                                    	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
                                                                                                    Caused by: org.xmlpull.v1.XmlPullParserException: Unexpected token (position:unknown @2:1 in java.io.InputStreamReader@3ecb104) 
                                                                                                    	at com.android.org.kxml2.io.KXmlParser.next(KXmlParser.java:436)
                                                                                                    	at com.android.org.kxml2.io.KXmlParser.next(KXmlParser.java:321)
                                                                                                    	at com.prof18.rssparser.internal.AndroidXmlParser$parseXML$2.invokeSuspend(AndroidXmlParser.kt:59)
                                                                                                    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
                                                                                                    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) 
                                                                                                    	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115) 
                                                                                                    	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103) 
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) 
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) 
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) 
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)  

I think the empty line at the starting of the rss feed is causing the exception, I have tested it by copy pasting the content of the rss feed as String and using the parseString method. The original rss with the empty line throws the exception, but when I remove the empty line it works as expected. Please look into it

The link of the RSS Feed https://inc42.com/buzz/feed/

mayank12gt avatar Feb 01 '24 09:02 mayank12gt