io.dylemma.spac.xml

This package provides extensions to the core "spac" library which allow for the handling of XML data.

Rather than creating explicit classes that extend Parser, Transformer, and Splitter, this package provides type aliases and implicit extensions. For example, XmlParser[A] is just a type alias for Parser[XmlEvent, A], and XmlParser is just a call to Parser[XmlEvent].

Three main Parser methods are added to Parser[XmlEvent] via the XmlParserApplyOps implicit class:

  • XmlParser.forText - for capturing raw text
  • XmlParser.attr - for capturing mandatory attributes from elements
  • XmlParser.attrOpt - for capturing optional attributes from elements

One main Splitter constructor method is added to Splitter via the XmlSplitterApplyOps implicit class:

  • Splitter.xml - for creating splitters based on an inspection of an "element stack"

Three main Splitter member methods are added to Splitter[XmlEvent, C] via the XmlSplitterOps implicit class:

  • .attr - alias for .joinBy(XmlParser.attr(...))
  • .attrOpt - alias for .joinBy(XmlParser.attrOpt(...))
  • .text - alias for .joinBy(XmlParser.forText)

A DSL for creating xml-specific ContextMatchers is provided to make it more convenient to call Splitter.xml. For example:

Splitter.xml("things" \ "thing").attr("foo").parseToList

Can be used to capture a list of the "foo" attributes in the <thing> elements in

<things>
   <thing foo="hello" />
   <thing foo="Goodbye">
      <extra>junk</extra>
   </thing>
</thing>

Attributes

Members list

Packages

Type members

Classlikes

trait AsQName[N]

Adapter for various representations of QName

Adapter for various representations of QName

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object AsQName

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
AsQName.type
sealed trait XmlEvent extends HasLocation

Spac's internal representation of XML "events". Third-party xml streaming classes like javax.xml.stream or fs2-data can be supported by providing an AsXmlEvent implementation which converts the third-party event type into this type.

Spac's internal representation of XML "events". Third-party xml streaming classes like javax.xml.stream or fs2-data can be supported by providing an AsXmlEvent implementation which converts the third-party event type into this type.

Attributes

Companion
object
Supertypes
trait HasLocation
class Object
trait Matchable
class Any
Known subtypes
trait ElemEnd
trait ElemStart
trait Text
object XmlEvent

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
XmlEvent.type
final implicit class XmlParserApplyOps(val parserApply: ParserApplyWithBoundInput[XmlEvent]) extends AnyVal

XML-specific Parser constructor methods, for example XmlParser.attr and XmlParser.text

XML-specific Parser constructor methods, for example XmlParser.attr and XmlParser.text

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
trait XmlSpacException[Self <: XmlSpacException[Self]] extends SpacException[Self]

SpacException subtype for XML-specific exceptions

SpacException subtype for XML-specific exceptions

Attributes

Companion
object
Supertypes
class SpacException[Self]
trait NoStackTrace
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all

Contains the actual XmlSpacException subtypes

Contains the actual XmlSpacException subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
final implicit class XmlSplitterApplyOps(val splitter: Splitter.type) extends AnyVal

Adds Splitter.xml, for constructing element matcher-based XmlSplitters.

Adds Splitter.xml, for constructing element matcher-based XmlSplitters.

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
implicit class XmlSplitterOps[C](splitter: Splitter[XmlEvent, C])

XML-specific Splitter member methods, for example: attr, attrOpt, and text,

XML-specific Splitter member methods, for example: attr, attrOpt, and text,

Attributes

Supertypes
class Object
trait Matchable
class Any

Types

type ElemContextMatcher[+A] = SingleItemContextMatcher[ElemStart, A]

Attributes

type XmlContextMatcher[+Context] = ContextMatcher[ElemStart, Context]

Attributes

type XmlParser[+Out] = Parser[XmlEvent, Out]

Type alias for a Parser whose input type is XmlEvent.

Type alias for a Parser whose input type is XmlEvent.

Attributes

type XmlSplitter[+C] = Splitter[XmlEvent, C]

Attributes

type XmlTransformer[+Out] = Transformer[XmlEvent, Out]

Attributes

Deprecated types

type XMLContextMatcher[+Context] = XmlContextMatcher[Context]

Attributes

Deprecated
true
type XMLParser[+Out] = XmlParser[Out]

Attributes

Deprecated
true
type XMLSplitter[+C] = XmlSplitter[C]

Attributes

Deprecated
true

Value members

Concrete methods

def attr[N : AsQName](attrName: N): ElemContextMatcher[String]

Context matcher that extracts the given attribute from the element at the head of the stack.

Context matcher that extracts the given attribute from the element at the head of the stack.

Type parameters

N

The name type - usually String, but can be any member of the [[AsQName]] typeclass. Note that for javax.xml.namespace.QName you will need to include the "spac-javax" support library.

Value parameters

attrName

The name of the attribute to extract

Attributes

def attrOpt[N : AsQName](attrName: N): ElemContextMatcher[Option[String]]

Context matcher that extracts the given optional attribute from the element at the head of the stack. If the attribute is missing from the head element, this matcher will succeed with a result of None, as opposed to the attr matcher which would fail.

Context matcher that extracts the given optional attribute from the element at the head of the stack. If the attribute is missing from the head element, this matcher will succeed with a result of None, as opposed to the attr matcher which would fail.

Type parameters

N

The name type - usually String, but can be any member of the [[AsQName]] typeclass. Note that for javax.xml.namespace.QName you will need to include the "spac-javax" support library.

Value parameters

attrName

The name of the attribute to extract

Attributes

Context matcher that extracts the (local) name of the element at the head of the stack. Acts as a convenience for extractElemQName[String]

Context matcher that extracts the (local) name of the element at the head of the stack. Acts as a convenience for extractElemQName[String]

Attributes

Context matcher that extracts the (qualified) name of the element at the head of the stack. The type-level representation of the name is chosen by the caller

Context matcher that extracts the (qualified) name of the element at the head of the stack. The type-level representation of the name is chosen by the caller

Type parameters

N

The representation of the element's qualified name. This could be String, but in that case you should use extractElemName instead. For QName types such as the one from javax.xml, you must import a corresponding support package.

Attributes

Concrete fields

val *: ElemContextMatcher[Unit]

Context matcher that matches any single element at the head of the tag stack.

Context matcher that matches any single element at the head of the tag stack.

Attributes

val **: XmlContextMatcher[Unit]

Context matcher that matches any number of elements from the head of the tag stack.

Context matcher that matches any number of elements from the head of the tag stack.

Attributes

val Root: XmlContextMatcher[Unit]

Context matcher that always matches without consuming any of the tag stack.

Context matcher that always matches without consuming any of the tag stack.

Attributes

val XmlParser: ParserApplyWithBoundInput[XmlEvent]

Like the Parser companion object, but only for creating Parsers whose input type is XmlEvent.

Like the Parser companion object, but only for creating Parsers whose input type is XmlEvent.

Attributes

See also
val XmlSplitter: SplitterApplyWithBoundInput[XmlEvent]

Attributes

val XmlTransformer: TransformerApplyWithBoundInput[XmlEvent]

Attributes

Deprecated fields

val XMLParser: ParserApplyWithBoundInput[XmlEvent]

Attributes

Deprecated
true
val XMLSplitter: SplitterApplyWithBoundInput[XmlEvent]

Attributes

Deprecated
true

Implicits

Implicits

final implicit def XmlParserApplyOps(parserApply: ParserApplyWithBoundInput[XmlEvent]): XmlParserApplyOps

XML-specific Parser constructor methods, for example XmlParser.attr and XmlParser.text

XML-specific Parser constructor methods, for example XmlParser.attr and XmlParser.text

Attributes

final implicit def XmlSplitterApplyOps(splitter: Splitter.type): XmlSplitterApplyOps

Adds Splitter.xml, for constructing element matcher-based XmlSplitters.

Adds Splitter.xml, for constructing element matcher-based XmlSplitters.

Attributes

final implicit def XmlSplitterOps[C](splitter: Splitter[XmlEvent, C]): XmlSplitterOps[C]

XML-specific Splitter member methods, for example: attr, attrOpt, and text,

XML-specific Splitter member methods, for example: attr, attrOpt, and text,

Attributes

implicit def elem[N](elemName: N)(implicit N: AsQName[N]): ElemContextMatcher[Unit]

Context matcher that matches the element at the head of the stack as long as its name matches the given elemName

Context matcher that matches the element at the head of the stack as long as its name matches the given elemName

This is normally called implicitly, e.g. with Splitter.xml("foo" \ "bar"), but of course can be called explicitly, e.g. val matcher = elem("foo") \ elem("bar")

Type parameters

N

The name type - usually String, but can be any member of the [[AsQName]] typeclass. Note that for javax.xml.namespace.QName you will need to include the "spac-javax" support library.

Value parameters

elemName

The name of the element.

Attributes