Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
xs4s/example/src/main/scala/xs4s/example/brief/BriefPlainScalaExample.scala
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
23 lines (19 sloc)
683 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package xs4s.example.brief | |
import java.io.File | |
/** An example that compiles but does not run - for use in the README */ | |
object BriefPlainScalaExample { | |
import xs4s._ | |
import xs4s.syntax.core._ | |
import scala.xml.Elem | |
def extractAnchorTexts(sourceFile: File): Unit = { | |
val anchorElementExtractor: XmlElementExtractor[Elem] = | |
XmlElementExtractor.filterElementsByName("anchor") | |
val xmlEventReader = XMLStream.fromFile(sourceFile) | |
try { | |
val elements: Iterator[Elem] = | |
xmlEventReader.extractWith(anchorElementExtractor) | |
val text: Iterator[String] = elements.map(_.text) | |
text.foreach(println) | |
} finally xmlEventReader.close() | |
} | |
} |