Skip to content

Instantly share code, notes, and snippets.

@koduki
Created May 16, 2010 15:46
Show Gist options
  • Save koduki/402942 to your computer and use it in GitHub Desktop.
Save koduki/402942 to your computer and use it in GitHub Desktop.
import java.io._
import scala.xml._
def tag2html(text:String) = text.replaceAll("<link caption=\"(.*?)\".*?>(.*?)</link>", "<a href='$2'>$1</a>").replaceAll("<link>(.*?)</link>", "<a href='$1'>$1</a>").replaceAll("<p>(.*?)</p>", "<pre>$1</pre>").replaceAll("<p>(.*?)</p>", "<pre>$1</pre>");
val blog_data = scala.xml.XML.loadFile(new File("/mnt/share/documents/blog.txt"))
val article = (blog_data \ "document") toList(3)
article \ "@id"
article \ "date" text
article \ "lastupdate" text
article \\ "group" map ( x => x.text)
article \\ "title" text
article \\ "group" map ( x => "[" + x.text + "]")
tag2html(article \\ "content" text)
val comments = article \\ "comment"
val comment = comments(0)
comment \ "@name" text
comment \ "@date" text
comment text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment