Pubmed fetch xml entry by ID

It wasn’t clear how to grab a pubmed entry in xml format given an ID. This is how to do it:

import{fromFile, fromInputStream}
import scala.xml._

val idFile = "medline_ids.txt"

val ids = fromFile( idFile ).getLines()

for ( i <- 0 until 1 ) {
  val url = new URL("" + + "&retmode=xml")
  println( url )
  val inStream = fromInputStream(url.openStream).getLines.mkString("\n")
  println( inStream ) 


The important part is this:

rather than which simply forces the output to look like xml. If you fetch the report=xml code using scala/curl you will see that all the are represented by their html codes – not nice.