summaryrefslogtreecommitdiff
path: root/src/xml/scala/xml/ProcInstr.scala
blob: 189c1c6878dd189ce6b44a22a474541020a07431 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2013, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */


package scala
package xml

/** an XML node for processing instructions (PI)
 *
 * @author Burak Emir
 * @param  target     target name of this PI
 * @param  proctext   text contained in this node, may not contain "?>"
 */
case class ProcInstr(target: String, proctext: String) extends SpecialNode
{
  if (!Utility.isName(target))
    throw new IllegalArgumentException(target+" must be an XML Name")
  if (proctext contains "?>")
    throw new IllegalArgumentException(proctext+" may not contain \"?>\"")
  if (target.toLowerCase == "xml")
    throw new IllegalArgumentException(target+" is reserved")

  final override def doCollectNamespaces = false
  final override def doTransform         = false

  final def label   = "#PI"
  override def text = ""

  /** appends "<?" target (" "+text)?+"?>"
   *  to this stringbuffer.
   */
  override def buildString(sb: StringBuilder) =
    sb append "<?%s%s?>".format(target, (if (proctext == "") "" else " " + proctext))
}