prof18/RSS-Parser

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

Closed this issue · 1 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/

I've tried the URL, and it's parsed correctly.
Screenshot 2024-03-17 at 14 37 22