操作XML


Package:scala.xml


APIs


Node extends NodeSeq

An abstract class representing XML with nodes of a labelled tree. This class contains an implementation of a subset of XPath for navigation.

在 object NodeSeq 中有定義
implicit def view(s : Seq[Node]) : NodeSeq
而 List 是 Seq 的子類



Text

The class Text implements an XML node for text (PCDATA). It is used in both non-bound and bound XML representations.


NodeSeq

This class implements a wrapper around Seq[Node] that adds XPath and comprehension methods.


scala.xml.Elem


The case class Elem extends the Node class, providing an immutable data object representing an XML element.

scala> val a = <a>WisdomFish.ORG</a>
a: scala.xml.Elem = <a>WisdomFish.ORG</a>

scala> a
res0: scala.xml.Elem = <a>WisdomFish.ORG</a>

尋找 TagName = <a>
scala> a \\ "a"
res1: scala.xml.NodeSeq = NodeSeq(<a>WisdomFish.ORG</a>)

name=value
scala> val abc = <a name="kuo, ChaoYi" age="19" />
abc: scala.xml.Elem = <a name="kuo, ChaoYi" age="19"></a>


{ } 轉譯符
'{' scala-expr '}'


scala.xml.NodeSeq.Empty

scala> var a = scala.xml.NodeSeq.Empty
a: scala.xml.NodeSeq = NodeSeq()

scala> a = <a n="Kuo" />
a: scala.xml.NodeSeq = <a n="Kuo"></a>


scala> <a> { if ( 100 < 200 ) <old>{ 1 + 2 }</old> else scala.xml.NodeSeq.Empty } </a>
res8: scala.xml.Elem = <a> <old>3</old> </a>



Reference



Comments