summaryrefslogtreecommitdiff
path: root/src/library/scala/xml/parsing/ConstructingParser.scala
blob: 020b9892a0cf70d5b62ac4f748bff5da1e3553c1 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2006, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$


package scala.xml.parsing

import java.io.File

import scala.io.Source

object ConstructingParser {

  def fromFile(inp: File, preserveWS: Boolean) = {
    val p = new ConstructingParser(Source.fromFile(inp), preserveWS)
    p.nextch
    p
  }

  def fromSource(inp: Source, preserveWS: Boolean) = {
    val p = new ConstructingParser(inp, preserveWS)
    p.nextch
    p
  }
}

/** An xml parser. parses XML and invokes callback methods of a MarkupHandler.
 *  Don't forget to call next.ch on a freshly instantiated parser in order to
 *  initialize it. If you get the parser from the object method, initialization
 *  is already done for you.
 *
 *<pre>
object parseFromURL {
  def main(args:Array[String]): Unit = {
    val url = args(0);
    val src = scala.io.Source.fromURL(url);
    val cpa = scala.xml.parsing.ConstructingParser.fromSource(src, false); // fromSource initializes automatically
    val doc = cpa.document();

    // let's see what it is
    val ppr = new scala.xml.PrettyPrinter(80,5);
    val ele = doc.docElem;
    Console.println("finished parsing");
    val out = ppr.format(ele);
    Console.println(out);
  }
}
</pre>
 */
class ConstructingParser(inp: Source, presWS:Boolean)
extends { val input = inp }
with ConstructingHandler
with ExternalSources
with MarkupParser  {

  // default impl. of Logged
  override def log(msg: String): Unit = {}

  val preserveWS = presWS
}