Packages

  • package root
    Definition Classes
    root
  • package scala
    Definition Classes
    root
  • package xml

    This library provides support for the XML literal syntax in Scala programs.

    This library provides support for the XML literal syntax in Scala programs.

    val planets: scala.xml.Elem = <planets>
      <planet id="earth">
        <title>Earth</title>
        <mass unit="kg">5.9742e24</mass>
        <radius unit="m">6378.14e3</radius>
      </planet>
      <planet id="mars">
        <title>Mars</title>
        <mass unit="kg">0.64191e24</mass>
        <radius unit="m">3397.0e3</radius>
      </planet>
    </planets>

    Additionally, you can mix Scala expressions in your XML elements by using the curly brace notation:

    val sunMass = 1.99e30
    val sunRadius = 6.96e8
    val star = <star>
      <title>Sun</title>
      <mass unit="kg">{ sunMass }</mass>
      <radius unit="m">{ sunRadius }</radius>
      <surface unit="m²">{ 4 * Math.PI * Math.pow(sunRadius, 2) }</surface>
      <volume unit="m³">{ 4/3 * Math.PI * Math.pow(sunRadius, 3) }</volume>
    </star>

    An XML element, for example <star/> and <planet/>, is represented in this library as a case class, scala.xml.Elem.

    The sub-elements of XML values share a common base class, scala.xml.Node.

    However, the non-element declarations found in XML files share a different common base class, scala.xml.dtd.Decl. Additionally, document type declarations are represented by a different trait, scala.xml.dtd.DTD.

    For reading and writing XML data to and from files, see scala.xml.XML. The default parser of XML data is the Xerces parser and is provided in Java by javax.xml.parsers.SAXParser.

    A less greedy XML reader can return data as a sequential collection of events, see scala.xml.pull.XMLEventReader.

    For more control of the input, use the parser written in Scala that is provided, scala.xml.parsing.ConstructingParser.

    For working with XHTML input, use scala.xml.parsing.XhtmlParser.

    For more control of the output, use the scala.xml.PrettyPrinter.

    Utility methods for working with XML data are provided in scala.xml.Utility.

    XML values in Scala are immutable, but you can traverse and transform XML data with a scala.xml.transform.RuleTransformer.

    Definition Classes
    scala
  • package dtd
    Definition Classes
    xml
  • package factory
    Definition Classes
    xml
  • package include
    Definition Classes
    xml
  • package parsing
    Definition Classes
    xml
  • ConsoleErrorHandler
  • ConstructingHandler
  • ConstructingParser
  • DefaultMarkupHandler
  • ExternalSources
  • FactoryAdapter
  • FatalError
  • MarkupHandler
  • MarkupParser
  • NoBindingFactoryAdapter
  • TokenTests
  • ValidatingMarkupHandler
  • XhtmlEntities
  • XhtmlParser
  • package persistent
    Definition Classes
    xml
  • package pull

    Classes needed to view an XML document as a series of events.

    Classes needed to view an XML document as a series of events. The document is parsed by an scala.xml.pull.XMLEventReader instance. You can treat it as an scala.collection.Iterator to retrieve the events, which are all subclasses of scala.xml.pull.XMLEvent.

    scala> val source = Source.fromString("""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <?instruction custom value="customvalue"?>
    <!DOCTYPE foo [
      <!ENTITY bar "BAR">
    ]><foo>Hello<bar>&bar;</bar><bar>></bar></foo>""")
    
    source: scala.io.Source = non-empty iterator
    
    scala> val reader = new XMLEventReader(source)
    reader: scala.xml.pull.XMLEventReader = non-empty iterator
    
    scala> reader.foreach{ println(_) }
    EvProcInstr(instruction,custom value="customvalue")
    EvText(
    )
    EvElemStart(null,foo,,)
    EvText(Hello)
    EvComment( this is a comment )
    EvElemStart(null,bar,,)
    EvText(BAR)
    EvElemEnd(null,bar)
    EvElemStart(null,bar,,)
    EvEntityRef(gt)
    EvElemEnd(null,bar)
    EvElemEnd(null,foo)
    EvText(
    
    )
    Definition Classes
    xml
  • package transform
    Definition Classes
    xml
p

scala.xml

parsing

package parsing

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. Protected

Type Members

  1. trait ConsoleErrorHandler extends DefaultHandler
  2. abstract class ConstructingHandler extends MarkupHandler

    Implementation of MarkupHandler that constructs nodes.

  3. class ConstructingParser extends ConstructingHandler with ExternalSources with MarkupParser

    An xml parser.

    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]) {
        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
        println("finished parsing")
        val out = ppr.format(ele)
        println(out)
      }
    }
  4. abstract class DefaultMarkupHandler extends MarkupHandler

    Default implementation of markup handler always returns NodeSeq.Empty

  5. trait ExternalSources extends AnyRef

  6. abstract class FactoryAdapter extends DefaultHandler with XMLLoader[Node]

    SAX adapter class, for use with Java SAX parser.

    SAX adapter class, for use with Java SAX parser. Keeps track of namespace bindings, without relying on namespace handling of the underlying SAX parser.

  7. case class FatalError(msg: String) extends java.lang.RuntimeException with Product with Serializable

    !!! This is poorly named, but I guess it's in the API.

  8. abstract class MarkupHandler extends AnyRef

    class that handles markup - provides callback methods to MarkupParser.

    class that handles markup - provides callback methods to MarkupParser. the default is nonvalidating behaviour

    To do

    can we ignore more entity declarations (i.e. those with extIDs)?

    expanding entity references

  9. trait MarkupParser extends MarkupParserCommon with TokenTests

    An XML parser.

    An XML parser.

    Parses XML 1.0, invokes callback methods of a MarkupHandler and returns whatever the markup handler returns. Use ConstructingParser if you just want to parse XML to construct instances of scala.xml.Node.

    While XML elements are returned, DTD declarations - if handled - are collected using side-effects.

  10. class NoBindingFactoryAdapter extends FactoryAdapter with NodeFactory[Elem]

    nobinding adaptor providing callbacks to parser to create elements.

    nobinding adaptor providing callbacks to parser to create elements. implements hash-consing

  11. trait TokenTests extends AnyRef

    Helper functions for parsing XML fragments

  12. class XhtmlParser extends ConstructingHandler with MarkupParser with ExternalSources

    An XML Parser that preserves CDATA blocks and knows about scala.xml.parsing.XhtmlEntities.

Deprecated Type Members

  1. abstract class ValidatingMarkupHandler extends MarkupHandler
    Annotations
    @deprecated
    Deprecated

    (Since version 1.3.0) This class will be removed

Value Members

  1. object ConstructingParser
  2. object XhtmlEntities

  3. object XhtmlParser

    Convenience method that instantiates, initializes and runs an XhtmlParser.

Ungrouped