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!