package 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 textXmlParser.attr
- for capturing mandatory attributes from elementsXmlParser.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>
- Source
- package.scala
- Grouped
- Alphabetic
- By Inheritance
- xml
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- trait AsQName[N] extends AnyRef
Adapter for various representations of QName
- type ElemContextMatcher[+A] = SingleItemContextMatcher[ElemStart, A]
- type XmlContextMatcher[+Context] = ContextMatcher[ElemStart, Context]
- sealed trait XmlEvent extends HasLocation
Spac's internal representation of XML "events".
Spac's internal representation of XML "events". Third-party xml streaming classes like
javax.xml.stream
orfs2-data
can be supported by providing anAsXmlEvent
implementation which converts the third-party event type into this type. - type XmlParser[+Out] = Parser[XmlEvent, Out]
Type alias for a
Parser
whose input type isXmlEvent
. - implicit final class XmlParserApplyOps extends AnyVal
XML-specific Parser constructor methods, for example
XmlParser.attr
andXmlParser.text
- trait XmlSpacException[Self <: XmlSpacException[Self]] extends SpacException[Self]
SpacException subtype for XML-specific exceptions
- type XmlSplitter[+C] = Splitter[XmlEvent, C]
- implicit final class XmlSplitterApplyOps extends AnyVal
Adds
Splitter.xml
, for constructing element matcher-based XmlSplitters. - implicit class XmlSplitterOps[C] extends AnyRef
XML-specific Splitter member methods, for example:
attr
,attrOpt
, andtext
, - type XmlTransformer[+Out] = Transformer[XmlEvent, Out]
Deprecated Type Members
- type XMLContextMatcher[+Context] = ContextMatcher[ElemStart, Context]
- Annotations
- @deprecated
- Deprecated
(Since version v0.9) Use
XmlContextMatcher (with lowercase 'ml') instead
- type XMLParser[+Out] = Parser[XmlEvent, Out]
- Annotations
- @deprecated
- Deprecated
(Since version v0.9) Use
XmlParser
(with lowercase 'ml') instead
- type XMLSplitter[+C] = Splitter[XmlEvent, C]
- Annotations
- @deprecated
- Deprecated
(Since version v0.9) Use
XmlSplitter
(with lowercase 'ml') instead
Value Members
- val *: ElemContextMatcher[Unit]
Context matcher that matches any single element at the head of the tag stack.
- val **: XmlContextMatcher[Unit]
Context matcher that matches any number of elements from the head of the tag stack.
- val Root: XmlContextMatcher[Unit]
Context matcher that always matches without consuming any of the tag stack.
- val XmlParser: ParserApplyWithBoundInput[XmlEvent]
Like the
Parser
companion object, but only for creating Parsers whose input type isXmlEvent
.Like the
Parser
companion object, but only for creating Parsers whose input type isXmlEvent
.- See also
- val XmlSplitter: SplitterApplyWithBoundInput[XmlEvent]
- val XmlTransformer: TransformerApplyWithBoundInput[XmlEvent]
- def attr[N](attrName: N)(implicit arg0: AsQName[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.
- N
The name *type* - usually
String
, but can be any member of theAsQName
typeclass. Note that forjavax.xml.namespace.QName
you will need to include the "spac-javax" support library.- attrName
The name of the attribute to extract
- def attrOpt[N](attrName: N)(implicit arg0: AsQName[N]): ElemContextMatcher[Option[String]]
Context matcher that extracts the given optional attribute from the element at the head of the stack.
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.- N
The name *type* - usually
String
, but can be any member of theAsQName
typeclass. Note that forjavax.xml.namespace.QName
you will need to include the "spac-javax" support library.- attrName
The name of the attribute to extract
- 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")
- N
The name *type* - usually
String
, but can be any member of theAsQName
typeclass. Note that forjavax.xml.namespace.QName
you will need to include the "spac-javax" support library.- elemName
The name of the element.
- def extractElemName: ElemContextMatcher[String]
Context matcher that extracts the (local) name of the element at the head of the stack.
Context matcher that extracts the (local) name of the element at the head of the stack. Acts as a convenience for
extractElemQName[String]
- def extractElemQName[N](implicit arg0: AsQName[N]): ElemContextMatcher[N]
Context matcher that extracts the (qualified) name of the element at the head of the stack.
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
- N
The representation of the element's qualified name. This could be
String
, but in that case you should useextractElemName
instead. For QName types such as the one fromjavax.xml
, you must import a corresponding support package.
- object AsQName
- object Fs2DataQName
- object Fs2DataSource
Provides helpers for creating FS2 streams of
io.dylemma.spac.xml.XmlEvent
, using fs2-data-xml as the underlying event provider.Provides helpers for creating FS2 streams of
io.dylemma.spac.xml.XmlEvent
, using fs2-data-xml as the underlying event provider.Fs2-data is already pretty "plug-and-play", so at best this helper just removes a few steps/pipes that you would have to manually call.
For example:
val charStream: Stream[IO, Char] = ??? // this... val xmlStream1: Stream[IO, XmlEvent] = { import fs2.data.xml._ charStream .through(events) .through(namespaceResolver) .through(reverenceResolver()) .through(normalize) .through(Fs2DataSource.convert) } // could be replaced with val xmlStream2: Stream[IO, XmlEvent] = { Fs2DataSource.fromRawXmlStream(charStream) }
Essentially this helper just provides a convenient
apply
method that acceptsString
,Stream[F, Char]
,Stream[F, String]
, orStream[F, fs2.data.xml.XmlEvent]
to return aStream[F, XmlEvent]
which anXmlParser
could then interact with. - object JavaxQName
- object JavaxSource
Provides helpers for creating
Source[XmlEvent]
usingjavax.xml.stream
for the underlying event provider. - object XmlEvent
- object XmlSpacException extends Serializable
Contains the actual
XmlSpacException
subtypes
Deprecated Value Members
- val XMLParser: ParserApplyWithBoundInput[XmlEvent]
- Annotations
- @deprecated
- Deprecated
(Since version v0.9) Use
XmlParser
(with lowercase 'ml') to reference the parser companion
- val XMLSplitter: SplitterApplyWithBoundInput[XmlEvent]
- Annotations
- @deprecated
- Deprecated
(Since version v0.9) Use
XmlSplitter
(with lowercase 'ml') for directly referencing the companion object, or useSplitter.xml
to construct a new XmlSplitter