Quantcast
Channel: Too many records extracted from RSS feed Scala - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Too many records extracted from RSS feed Scala

$
0
0

I need to extract some data from XML and write it to the database. I have created Record entity for that:

case class Record (title: String, description: String)

I want to write titles and descriptions to Record entities. If I have about 12 records in XML I want to have an output of 12 records. However, I get an output of 12*12 records, which means each record is printed 12 times. What may be the reason of it?

Here is the main method:

def main(args: Array[String]): Unit = {    val response: HttpResponse[String] = Http("link")      .timeout(connTimeoutMs = 2000, readTimeoutMs = 5000)      .asString    val xmlString = response.body    val xml = XML.loadString(xmlString)    val titleNodes = (xml \\ "item" \ "title")    val descriptionNodes = (xml \\ "item" \ "description")    val output: Seq[Record] = for{      title <- titleNodes      description <- descriptionNodes    }yield Record(title.text, description.text)    output.foreach(println)}

I have started to code in Scala only recently so I would be grateful for any advice!


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>