本文整理汇总了Scala中scala.xml.Text类的典型用法代码示例。如果您正苦于以下问题:Scala Text类的具体用法?Scala Text怎么用?Scala Text使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Text类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: TrainPage
//设置package包名称以及导入依赖的类
package scrape.model
import scala.util.Try
import scala.xml.{NodeSeq, Text}
case class TrainPage(
name: String,
number: String,
code: Option[Int],
stops: List[StopDetail],
url: String,
car: List[String],
remark: List[String],
day: String
)
object TrainPage {
import utils.ParseHelper._
def fromXML(xml: NodeSeq, url: String): Either[String, TrainPage] = {
import utils.EitherUtil.eitherToRightProjection
for {
container <- (xml \\ "div" find (_ \ "@id" contains Text("container02"))).toRight("container")
table <- (container \\ "table" find (_ \ "@cellpadding" contains Text("5"))).toRight("table")
trs = table \ "tbody" \ "tr"
name <- extractValueFromTr(trs, 0)(norm).toRight("name")
number <- extractValueFromTr(trs, 1)(norm).toRight("number")
code = extractValueFromTr(trs, 2)(norm).flatMap { it => Try(it.toInt).toOption }
car <- extractValueFromTr(trs, 3)(normList(',')).toRight("car")
remark <- extractValueFromTr(trs, 4)(normList(',')).toRight("remark")
day <- extractValueFromTr(trs, 5)(norm).toRight("day")
stops = trs.view(8, trs.length).flatMap(StopDetail.fromXML).toList
} yield { TrainPage(name.replace(norm("?"), "?"), number, code, stops, url, car, remark, day) }
}
private def extractValueFromTr[A](xml: NodeSeq, index: Int)(f: String => A): Option[A] = for {
line <- xml.lift(index)
raw <- (line \ "td").lift(1)
} yield f((raw \ "span").text)
}
开发者ID:ponkotuy,项目名称:train-stamp-rally,代码行数:41,代码来源:TrainPage.scala
示例2: SelectionController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller}
import scala.xml.{Node, Text}
class SelectionController @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport {
def index() = Action {
implicit request => val xml : UserXML = xmlForm.bindFromRequest().get
val p = scala.xml.XML.loadString(xml.xml)
val pageId = (p \ "state" \ "page-id").text
val title = (p \ "header" \ "title").text
val selections = p \ "selection"
var selection = selections
for (e <- selections){
if ((e \ "@page-id").text == pageId){
selection = e
}
}
// val selection = (p \\ "_").filter(attributeEquals("@page-id", Text(pageId)))
val header1 = (selection \ "header1").text
val header2 = (selection \ "header2").text
val options = selection \ "option"
var optionsCode : String = ""
for (e <- options){
val mapToEncode = Map("page-id"->(selection \ "next").text, (selection \ "@tag")-> (e \ "@short"))
var stringMap = ""
for ((k, v) <- mapToEncode) {
stringMap = stringMap + k + "=" + v + ":"
}
optionsCode += "<form method=\"POST\" action=\"/bind/\" style=\"text-align: center\">" +
"<input type=\"text\" name=\"xml\" value=\"" + scala.xml.Utility.escape(xml.xml) + "\" style=\"display: none\" />" +
"<input type=\"text\" name=\"map\" value=\"" + stringMap + "\" style=\"display: none\" />" +
"<input type=\"submit\" value=\"> " + (e \ "@value").text + "\" class=\"answer\" onMouseOver=\"document.getElementById('description').innerHTML = '" + e.text + "';\" onMouseOut=\"document.getElementById('description').innerHTML = '';\"/>" +
"</form>"
}
Ok(views.html.main(title)(content = views.html.selection(header1, header2, optionsCode, xml.xml)))
}
def attributeEquals(name: String, value: Text)(node: Node) = node.attributes.exists(_ == value)
val xmlForm = Form(
mapping(
"xml" -> nonEmptyText
)(UserXML.apply)(UserXML.unapply)
)
}
开发者ID:Peantab,项目名称:paragraph-framework,代码行数:56,代码来源:SelectionController.scala
示例3: TextController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller}
import scala.xml.{Node, Text}
class TextController @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport {
def index() = Action {
implicit request => val xml : UserXML = xmlForm.bindFromRequest().get
val p = scala.xml.XML.loadString(xml.xml)
val pageId = (p \ "state" \ "page-id").text
val title = (p \ "header" \ "title").text
val texts = p \ "text"
var text = texts
for (e <- texts){
if ((e \ "@page-id").text == pageId){
text = e
}
}
val header1 = (text \ "header1").text
val header2 = (text \ "header2").text
val tag = (text \ "@tag").text
val default = (text \ "@default").text
val accept = "> " + (text \ "@accept").text
val nextPage = (text \ "next").text
Ok(views.html.main(title)(content = views.html.text(header1, header2, tag, default, accept, nextPage, xml.xml)))
}
def attributeEquals(name: String, value: Text)(node: Node) = node.attributes.exists(_ == value)
val xmlForm = Form(
mapping(
"xml" -> nonEmptyText
)(UserXML.apply)(UserXML.unapply)
)
}
开发者ID:Peantab,项目名称:paragraph-framework,代码行数:44,代码来源:TextController.scala
示例4: ExerciseEight
//设置package包名称以及导入依赖的类
package chapter.sixteen
import scala.collection.mutable.Map
import scala.xml.{ Elem, Text }
object ExerciseEight {
def dlToMap(dl: Elem): Map[String, String] = {
val map = Map[String, String]()
val children = dl.child
require(children.size % 2 == 0)
for (i <- children.indices by 2) {
(children(i), children(i + 1)) match {
case (<dt>{Text(key)}</dt>, <dd>{Text(value)}</dd>) => map(key) = value
case _ => ; // throw exception?
}
}
map
}
}
开发者ID:deekim,项目名称:impatient-scala,代码行数:24,代码来源:ExerciseEight.scala
示例5: SimpleTransformationStd
//设置package包名称以及导入依赖的类
package net.michalsitko.xml.bench
import java.io.StringWriter
import scala.xml.{Elem, Node, Text, XML}
object SimpleTransformationStd extends SimpleTransformation {
val doTransform: PartialFunction[Node, Node] = {
case el: Elem if el.label == "f" =>
if(el.child.size == 1) {
val replaceWith = el.child.head match {
case t: Text =>
Text(t.text.toUpperCase)
case a => a
}
el.copy(child = List(replaceWith))
} else {
el
}
case a => a
}
override def transform(input: String): String = {
val xml = XML.loadString(input)
val transformed = xml.map {
case el: Elem if el.label == "a" =>
el.copy(child = el.child.flatMap { el =>
doTransform(el)
})
case a => a
}
val writer = new StringWriter
XML.write(writer, transformed.head, "UTF-8", true, null)
writer.toString
}
}
开发者ID:note,项目名称:xml-lens,代码行数:40,代码来源:SimpleTransformationStd.scala
示例6: Util
//设置package包名称以及导入依赖的类
package trap.xml
//import java.io.BufferedInputStream
//import java.io.BufferedOutputStream
//import java.io.BufferedReader
//import java.io.File
import java.io.FileInputStream
import java.io.InputStreamReader
import scala.xml.Elem
import scala.xml.Attribute
import scala.xml.Text
import scala.xml.Node
import scala.xml.NodeSeq
import scala.xml.Null
import scala.xml.PrettyPrinter
import scala.xml.XML
import trap.Util._
import trap.file.Util._
object Util {
def formatNicely(xmlFile:String) =
writeToTextFile(xmlFile, new PrettyPrinter(200, 2).format(loadXML(xmlFile)))
def formatNicely(xml:Elem) = new PrettyPrinter(200, 2).format(xml)
def getAttributeText(xml:NodeSeq, attrName:String) = {
printdbg (" ===> getAttributeTest "+xml+": "+attrName)
(xml \ ("@"+attrName)).text
}
private val r = <root/>
def getNode(n:String) = r.copy(label=n)
def addChild(n: Node, newChild: Node) = n match {
case Elem(prefix, label, attribs, scope, child @ _*) =>
Elem(prefix, label, attribs, scope, child ++ newChild : _*)
case _ => throw new Exception("Can only add children to elements!")
}
def addChildren(n:Node, children:NodeSeq) = children.foldLeft(n)((x, y) => addChild(x, y))
def addAttribute(n:Elem, attrName:String, attrValue:String) = n % Attribute(None, attrName, Text(attrValue), Null)
def attr(xml:Node, attrName:String) = (xml \ ("@"+attrName)).text
def loadXML(fileName:String) =
using(new FileInputStream(fileName)){
fis => using(new InputStreamReader(fis)){
isr => XML.load(isr)
}
}
def getElementName (x:Node) = x.nameToString(new StringBuilder).toString
def filterByAttr(xml:NodeSeq, attrName:String, attrValue:String) =
xml.filter(x => (x \ ("@"+attrName)).text == attrValue)
def getElementsWithAttribute(xml:NodeSeq, elementName:String, attrName:String, attrVal:String) =
xml \ elementName collect { x => (x \ ("@"+attrName)).map(_.text).contains(attrVal) match {
case true => x
}
}
def getElementWithAttribute(xml:NodeSeq, elementName:String, attrName:String, attrVal:String) =
((xml \ elementName).find{ x => (x \ ("@"+attrName)).map(_.text).contains(attrVal) }).get
def getChildren(xml:NodeSeq) = xml \ "_"
}
开发者ID:scalahub,项目名称:acc,代码行数:60,代码来源:Util.scala
示例7: MySnippet
//设置package包名称以及导入依赖的类
package code.snippet
import net.liftweb.http.js.JsCmd
import net.liftweb.http.js.JsCmds.SetHtml
import net.liftweb.http.SHtml
import net.liftweb.util.Helpers._
import scala.xml.Text
class MySnippet {
def render = {
var count: Int = 0
def buttonClicked(): JsCmd = {
count = count + 1
SetHtml("result", Text(s"You clicked me $count times"))
}
"button" #> SHtml.ajaxButton("Click Me", () ? buttonClicked())
}
}
开发者ID:channingwalton,项目名称:lift-example,代码行数:23,代码来源:MySnippet.scala
示例8: Clock
//设置package包名称以及导入依赖的类
package code.comet
import net.liftweb.http.{CometActor, RenderOut}
import net.liftweb.http.js.JsCmds.SetHtml
import net.liftweb.util.Schedule
import net.liftweb.util.TimeHelpers.now
import scala.xml.{Elem, Text}
class Clock extends CometActor {
case object Tick
// schedule a Tick periodically
private val updatePeriod = 1000L
Schedule.schedule(this, Tick, updatePeriod)
def render: RenderOut =
"time" #> timeSpan
def timeSpan: Elem =
<span id="time">{now}</span>
override def lowPriority : PartialFunction[Any, Unit] = {
case Tick =>
// send a little Javascript to the browser to set the contents of
// the element with an id of 'time' to the current time.
partialUpdate(SetHtml("time", Text(now.toString)))
// schedule another update in 1 second
Schedule.schedule(this, Tick, updatePeriod)
}
}
开发者ID:channingwalton,项目名称:lift-example,代码行数:34,代码来源:Clock.scala
注:本文中的scala.xml.Text类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论