scala.xml.parsing

ConstructingParser

class ConstructingParser extends ConstructingHandler with ExternalSources with MarkupParser

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.

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);
}
}

Inherits

  1. MarkupParser
  2. MarkupParserCommon
  3. TokenTests
  4. ExternalSources
  5. ConstructingHandler
  6. MarkupHandler
  7. Logged
  8. AnyRef
  9. Any

Type Members

  1. type PositionType = Int

Value Members

  1. def appendText(pos: Int, ts: NodeBuffer, txt: String): Unit

  2. def attListDecl(name: String, attList: List[AttrDecl]): Unit

  3. def attrDecl(): Unit

    <! attlist := ATTLIST

  4. var ch: Char

    holds the next character

  5. def checkPubID(s: String): Boolean

  6. def checkSysID(s: String): Boolean

  7. def comment(pos: Int, txt: String): Comment

    callback method invoked by MarkupParser after parsing comment

  8. def content(pscope: NamespaceBinding): NodeSeq

    content1 ::= '<' content1 | '&' charref

  9. def content1(pscope: NamespaceBinding, ts: NodeBuffer): Unit

    '<' content1 ::=

  10. var curInput: Source

  11. var decls: List[Decl]

  12. def document(): Document

    [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') [25] Eq ::= S? '=' S? [26] VersionNum ::= '1

  13. var dtd: DTD

  14. def elem(pos: Int, pre: String, label: String, attrs: MetaData, pscope: NamespaceBinding, nodes: NodeSeq): NodeSeq

    callback method invoked by MarkupParser after parsing an elementm, between the elemStart and elemEnd callbacks

  15. def elemDecl(n: String, cmstr: String): Unit

  16. def elemEnd(pos: Int, pre: String, label: String): Unit

    callback method invoked by MarkupParser after end-tag of element

  17. def elemStart(pos: Int, pre: String, label: String, attrs: MetaData, scope: NamespaceBinding): Unit

    callback method invoked by MarkupParser after start-tag of element

  18. def element(pscope: NamespaceBinding): NodeSeq

  19. def element1(pscope: NamespaceBinding): NodeSeq

    '<' element ::= xmlTag1 '>' { xmlExpr | '{' simpleExpr '}' } ETag | xmlTag1 '/' '>'

  20. def elementDecl(): Unit

    <! element := ELEMENT

  21. def endDTD(n: String): Unit

  22. var ent: Map[String, EntityDecl]

  23. def entityDecl(): Unit

    <! element := ELEMENT

  24. def entityRef(pos: Int, n: String): EntityRef

    callback method invoked by MarkupParser after parsing entity ref

  25. var eof: Boolean

  26. def equals(arg0: Any): Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence

  27. var extIndex: Int

  28. def extSubset(): Unit

  29. def externalID(): ExternalID

    externalID ::= SYSTEM S syslit PUBLIC S pubid S syslit

  30. def externalSource(systemId: String): Source

  31. def hashCode(): Int

    Returns a hash code value for the object

  32. def initialize: MarkupParser with MarkupHandler

    As the current code requires you to call nextch once manually after construction, this method formalizes that suboptimal reality

  33. var inpStack: List[Source]

    stack of inputs

  34. val input: Source

  35. def intSubset(): Unit

    "rec-xml/#ExtSubset" pe references may not occur within markup declarations

  36. def isAlpha(c: Char): Boolean

    These are 99% sure to be redundant but refactoring on the safe side

  37. def isAlphaDigit(c: Char): Boolean

  38. def isName(s: String): Boolean

    Name ::= ( Letter | '_' ) (NameChar)*

  39. def isNameChar(ch: Char): Boolean

    NameChar ::= Letter | Digit | '

  40. def isNameStart(ch: Char): Boolean

    NameStart ::= ( Letter | '_' ) where Letter means in one of the Unicode general categories { Ll, Lu, Lo, Lt, Nl }

  41. def isPubIDChar(ch: Char): Boolean

  42. def isValidIANAEncoding(ianaEncoding: Seq[Char]): Boolean

    Returns true if the encoding name is a valid IANA encoding

  43. val isValidating: Boolean

    returns true is this markup handler is validating

  44. def log(msg: String): Unit

    This method should log the message given as argument somewhere as a side-effect

  45. def lookupElemDecl(Label: String): ElemDecl

  46. def markupDecl(): Unit

  47. def markupDecl1(): Any

  48. def nextch: Char

    this method assign the next character to ch and advances in input

  49. def normalizeAttributeValue(attval: String): String

    for the moment, replace only character references see spec 3

  50. def notationDecl(): Unit

    'N' notationDecl ::= "OTATION"

  51. def notationDecl(notat: String, extID: ExternalID): Unit

  52. def parameterEntityDecl(name: String, edef: EntityDef): Unit

  53. def parseDTD(): Unit

    parses document type declaration and assigns it to instance variable dtd

  54. def parsedEntityDecl(name: String, edef: EntityDef): Unit

  55. def peReference(name: String): Unit

  56. def pop(): Unit

  57. var pos: Int

    holds the position in the source file

  58. val preserveWS: Boolean

    if true, does not remove surplus whitespace

  59. def procInstr(pos: Int, target: String, txt: String): ProcInstr

    callback method invoked by MarkupParser after parsing PI

  60. def prolog(): (Option[String], Option[String], Option[Boolean])

    <? prolog ::= xml S? // this is a bit more lenient than necessary

  61. def pubidLiteral(): String

  62. def push(entityName: String): Unit

  63. def pushExternal(systemId: String): Unit

  64. def replacementText(entityName: String): Source

  65. def reportSyntaxError(str: String): Unit

  66. def reportSyntaxError(pos: Int, str: String): Unit

    PublicID (without system, only used in NOTATION)

  67. def reportValidationError(pos: Int, str: String): Unit

  68. def returning[T](x: T)(f: (T) ⇒ Unit): T

  69. def systemLiteral(): String

    attribute value, terminated by either ' or "

  70. def text(pos: Int, txt: String): Text

    callback method invoked by MarkupParser after parsing text

  71. def textDecl(): (Option[String], Option[String])

    prolog, but without standalone

  72. var tmppos: Int

    holds temporary values of pos

  73. def toString(): String

    Returns a string representation of the object

  74. def unparsedEntityDecl(name: String, extID: ExternalID, notat: String): Unit

  75. def xAttributeValue(): String

    attribute value, terminated by either ' or "

  76. def xAttributes(pscope: NamespaceBinding): (MetaData, NamespaceBinding)

    parse attribute and create namespace scope, metadata [41] Attributes ::= { S Name Eq AttValue }

  77. def xCharData: NodeSeq

    '<! CharData ::= [CDATA[ ( {char} - {char}"]]>"{char} ) ']]>'

  78. def xCharRef(ch: () ⇒ Char, nextch: () ⇒ Unit): String

    CharRef ::= "&#" '0'

  79. def xComment: NodeSeq

    Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'

  80. def xEQ: Unit

    scan [S] '=' [S]

  81. def xEndTag(n: String): Unit

    [42] '<' xmlEndTag ::= '<' '/' Name S? '>'

  82. def xEntityValue(): String

    entity value, terminated by either ' or "

  83. def xHandleError(that: Char, msg: String): Unit

  84. def xName: String

    Name ::= (Letter | '_' | ':') (NameChar)*

  85. def xProcInstr: NodeSeq

    '<?' ProcInstr ::= Name [S ({Char} - ({Char}'>?' {Char})]'?>'

  86. def xSpace: Unit

    scan [3] S ::= (#x20 | #x9 | #xD | #xA)+

  87. def xSpaceOpt: Unit

    skip optional space S?

  88. def xText: String

    parse character data

  89. def xToken(that: Seq[Char]): Unit

  90. def xToken(that: Char): Unit

  91. def xmlProcInstr(): MetaData

    <? prolog ::= xml S

Instance constructors

  1. new ConstructingParser(input: Source, preserveWS: Boolean)

  2. new ConstructingParser()