Skip to content

Instantly share code, notes, and snippets.

@chris-twiner
Created August 2, 2012 20:00
Show Gist options
  • Select an option

  • Save chris-twiner/3240166 to your computer and use it in GitHub Desktop.

Select an option

Save chris-twiner/3240166 to your computer and use it in GitHub Desktop.
Selecting attributes in Scales
// http://stackoverflow.com/questions/11758607/selecting-a-xml-attribute
// See https://github.com/chris-twiner/scalesXml for details on how to use
// save this as loadme.scalaScript and use :load loadme.scalaScript in the repl
import scales.utils.top
import scales.xml._
import ScalesXml._
import Functions._
val reportxml = """<wrapper>
<Sample Id="SomeId1">
<Tag Id="SomeTag">
<Lane Id="1">
[...]
</Lane>
</Tag>
</Sample>
<Sample Id="SomeId2">
<Tag Id="SomeTag">
<Lane Id="1">
[...]
</Lane>
</Tag>
</Sample>
</wrapper>"""
val report = loadXml(new java.io.StringReader(reportxml))
val sampleIds = top(report).\*("Sample"l).\@("Id"l)
val first = text(sampleIds)
val all = sampleIds.map(text(_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment