com.codecommit

antixml

package antixml

Base package for the Anti-XML framework. Note that importing this package brings in a number of implicit conversions. Specifically:

Source
package.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. antixml
  2. LowPrioritiyImplicits
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. class Attributes extends Map[QName, String] with MapLike[QName, String, Attributes]

    A special implementation of scala.collection.Map[com.codecommit.antixml.QName, String] with nice overloading and some implicit magic designed for use containing element attributes in com.codecommit.antixml.Elem.

    A special implementation of scala.collection.Map[com.codecommit.antixml.QName, String] with nice overloading and some implicit magic designed for use containing element attributes in com.codecommit.antixml.Elem. The actual stored keys are of type com.codecommit.antixml.QName. This is how (optional) namespace information for attributes is stored in Anti-XML trees. However, there are some syntactic tricks which allow you to ignore the com.codecommit.antixml.QName boiler-plate when you don't actually need namespace support. For example:

    val attrs = Attributes("foo" -> "bar", "baz" -> "bin")
    attrs("foo")                  // => "bar"
    attrs(QName(None, "foo"))     // => "bar"
    
    val attrs2 = attrs + ("even" -> "more")                       // => Attributes(...)
    val attrs3 = attrs + (QName(Some("pre"), "even" -> "less")    // => Attributes(...)

    With very, very few exceptions, String and com.codecommit.antixml.QName are interchangable. Of course, this is being done with implicit conversions. However, you don't need to worry about the conversion String => QName poluting the implicit dispatch space! The conversion is defined on the companion object for com.codecommit.antixml.QName, meaning that the compiler will only select it when the result of an expression is explicitly of type QName. It will not automatically inject the conversion to satisfy method dispatch on String. For example:

    val str = "fubar"
    
    val qn: QName = str      // works!
    str.ns                   // won't compile!

    In this example, it is important to note that ns is a method on com.codecommit.antixml.QName. Thus, if the implicit conversion were pimp-enabling, the compiler would have accepted the last line of the example. However, as you can see, the implicit dispatch space has not been cluttered while the convenience of String rather than com.codecommit.antixml.QName has been preserved.

    One implicit space-cluttering that couldn't be avoided is the conversion defined as (String, String) => (QName, String). This is required to enable the nice String syntax on things like the + method and the companion object apply factory. Unfortunately, this conversion had to be defined in the com.codecommit.antixml companion object. Fortunately, it is a conversion within the same type (simply different parameters passed to Tuple2). Thus, it shouldn't cause any scoping problems.

    See also

    com.codecommit.antixml.QName

  2. case class CDATA(text: String) extends Node with Product with Serializable

    A node containing a single string, representing unescaped character data in the XML tree.

    A node containing a single string, representing unescaped character data in the XML tree. For example:

    <![CDATA[Lorem ipsum & dolor sit amet]]>

    This would result in the following node:

    CDATA("Lorem ipsum & dolor sit amet")

    Note that reserved characters (as defined by the XML 1.0 spec) are not escaped when calling toString. If you need a text representation which performs escaping, use com.codecommit.antixml.Text

  3. trait CanBuildFromWithZipper[-From, -Elem, To] extends AnyRef

    A factory for com.codecommit.antixml.Zipper instances.

    A factory for com.codecommit.antixml.Zipper instances.

    WARNING: This is a "low-level" trait that was primarily designed for internal use of the antixml package. It is tied to the Zipper implementation and could change significantly in a future release.

    This trait is similar to CanBuildFrom, except that it allows a zipper context to be specified in addition to the usual sequence of items. See the com.codecommit.antixml.Zipper trait for the definition of "zipper context".

    The Builder produced by this class accepts objects of type com.codecommit.antixml.CanBuildFromWithZipper.ElemsWithContext. These objects contain the following information:

    • A sequence of items (nodes) to be added to the zipper.
    • A path specifying the hole associated with the above items.
    • An update counter, which indicates the relative order in which the zipper's items were last updated. This information is used by some com.codecommit.antixml.ZipperMergeStrategy implementations when resolving conflicts.

    Note that an ElemsWithContext may contain an empty sequence, in which case its path (hole) is added to zipper context without being associated to any items. Also note that it is legal for the same path (hole) to be added to the Builder multiple times. The resulting Zipper will associate all of the corresponding items to that hole.

    The parent of the zipper context is specified to the apply method of this trait.

    From

    The type of collection that is producing the zipper.

    Elem

    The type of nodes to be contained in the result (if any).

    To

    the type of collection being produced.

    See also

    com.codecommit.antixml.Zipper

  4. trait CanProduceZipper[-From, A <: Node, To] extends AnyRef

    A marker interface for scala.collection.mutable.CanBuildFrom instances that can be lifted into com.codecommit.antixml.CanBuildFromWithZipper instances that operate on com.codecommit.antixml.Node types.

  5. class Converter[A] extends AnyRef

    Pimp container for the explicit conversions into Anti-XML types.

    Pimp container for the explicit conversions into Anti-XML types. Out of the box, conversions are provided from scala.xml types. However, this mechanism is very extensible due to the use of a typeclass (com.codecommit.antixml.XMLConvertable) to represent the actual conversion. Thus, it is possible to add conversions by defining an implicit instance of the typeclass and having it in scope. It is even possible to override the built-in conversions for scala.xml types simply by shadowing the conversions for types like scala.xml.Elem. The built-in conversions are defined in such a way that Scala's implicit resolution will give precedence to almost anything you define, as long as it is somehow in scope.

  6. case class Elem(prefix: Option[String], name: String, attrs: Attributes = Attributes(), namespaces: NamespaceBinding = NamespaceBinding.empty, children: Group[Node] = Group.empty) extends Node with Selectable[Elem] with Product with Serializable

    An XML element consisting of an optional namespace prefix, a name (or identifier), a set of attributes, a namespace prefix scope (mapping of prefixes to namespace URIs), and a sequence of child nodes.

    An XML element consisting of an optional namespace prefix, a name (or identifier), a set of attributes, a namespace prefix scope (mapping of prefixes to namespace URIs), and a sequence of child nodes. For example:

    <span id="foo" class="bar">Lorem ipsum</span>

    This would result in the following node:

    Elem(None, "span", attrs = Attributes("id" -> "foo", "class" -> "bar"), children = Group(Text("Lorem ipsum")))

    TODO: Consider making Elem not a case class and handle thing a different way.

  7. case class EntityRef(entity: String) extends Node with Product with Serializable

    A node representing an entity reference.

    A node representing an entity reference. For example:

    &hellip;

    This would result in the following node:

    EntityRef("hellip")
  8. case class FQName(uri: String, local: String, defaultPrefix: Option[String] = None) extends Product with Serializable

  9. class Group[+A <: Node] extends IndexedSeq[A] with IndexedSeqLike[A, Group[A]] with Selectable[A]

    Represents a collection of arbitrary nodes (com.codecommit.antixml.Node)).

    Represents a collection of arbitrary nodes (com.codecommit.antixml.Node)). Note that this collection need not have a single root parent element. Thus, a valid Group could be as follows:

    Group(EntityRef("quot"), Text("Daniel is "), Elem(None, "em", Attributes(), Map(), Group(Text("delusional!"))), EntityRef("quot"))

    This would correspond to the following XML fragment (note: not actually well-formed XML, since it is lacking a single root element):

    &quot;Daniel is <em>delusional!</em>&quot;

    Note that unlike scala.xml, Group is not a special type of com.codecommit.antixml.Node! This design decision has a very profound impact on the framework as a whole. In general, the result is an API which is more consistent and more predictable than it otherwise would have been. However, it also resulted in some unfortunate sacrifices: specifically, full XPath semantics. The exact semantics of the \ and \\ operators are defined in their respective scaladocs.

    Group is parameterized based on the type of Node it contains. In the general case (such as the one illustrated above), this will be exactly Node. However, there are some very common cases wherein a Group may have a more specific type than just Node. For example:

    val ns: Group[Node] = ...
    val results = ns \ "name"

    In this example, results will have type Group[Elem]. This is because the selector employed ("name") can only produce results of type Elem. This mechanism forms the basis for the typed selectors mechanism, which is extremely powerful and serves to eliminate a great deal of boiler-plate casting when traversing XML hierarchies.

    In the general case, Group is backed by an instance of scala.collection.immutable.Vector. This implementation detail is significant as it implies two things. First, the implementation of Group is truly immutable, meaning that there are no tricky concurrency semantics to worry about. Second, unlike scala.xml (which backs its sequences by either List or ArrayBuffer, depending on phase of the moon), it is possible to perform efficient random-access and updates across the entire Group. Random access is implemented by the apply method, while random "updates" are implemented by the updated method. Fast prepend and append operations are also available.

    Beyond this, all standard collection operations are available on Group (e.g. flatMap, exists, collect, slice, etc). The appropriate incantations have been spoken to allow these methods to return the correct type. Thus, if you map over a Group and your function returns something which extends Node, the result will be a Group. If your function returns something which does not extend Node (e.g. Int), then the result will be something else (probably a generic IndexedSeq backed by Vector). Group itself extends scala.collection.immutable.IndexedSeq and thus can be used in situations which require this abstraction.

  10. trait LowPrioritiyImplicits extends AnyRef

    Allow these to be mixed in where needed, instead of having to import the package object.

  11. sealed class NSRepr extends AnyRef

  12. case class NamespaceBinding(bindings: List[NamespaceEntry] = List.empty) extends Iterable[NamespaceEntry] with Product with Serializable

  13. sealed trait NamespaceEntry extends AnyRef

  14. sealed trait Node extends AnyRef

    Root of the Node ADT, representing the different types of supported XML nodes which may appear in an XML fragment.

    Root of the Node ADT, representing the different types of supported XML nodes which may appear in an XML fragment. The ADT itself has the following shape (Haskell syntax):

    type Prefix = Maybe String
    type Scope = Map String String
    
    data Node = ProcInstr String String
              | Elem Prefix String Attributes Scope (Group Node)
              | Text String
              | CDATA String
              | EntityRef String

    For those that don't find Haskell to be the clearest explanation of what's going on in this type, here is a more natural-language version. The Node trait is sealed and has exactly four subclasses, each implementing a different type of XML node. These four classes are as follows:

  15. class NodeSeqSAXHandler extends DefaultHandler2

    Defines a SAX2 handler which produces an instance of com.codecommit.antixml.Group[com.codecommit.antixml.Elem] as a result.

    Defines a SAX2 handler which produces an instance of com.codecommit.antixml.Group[com.codecommit.antixml.Elem] as a result. This is the handler which is used internally by com.codecommit.antixml.SAXParser. It is provided as part of the public API to allow Anti-XML to be used with alternative SAX2 event sources (such as HTML parsers like TagSoup). The resulting com.codecommit.antixml.Group is obtained (at the conclusion of the parse) from the result() method.

    See also

    com.codecommit.antixml.SAXParser

  16. trait OptimizingSelector[+A] extends Selector[A]

  17. case class PrefixedNamespaceBinding(_prefix: String, _uri: String) extends NamespaceEntry with Product with Serializable

  18. case class ProcInstr(target: String, data: String) extends Node with Product with Serializable

    A processing instruction consisting of a target and some data.

    A processing instruction consisting of a target and some data. For example:

    <?xml version="1.0"?>

    This would result in the following node:

    ProcInstr("xml", "version=\"1.0\"")
  19. case class QName(prefix: Option[String], name: String) extends Product with Serializable

  20. class SAXParser extends XMLParser

    An XML parser build on top of org.w3c.sax.

    An XML parser build on top of org.w3c.sax. This implements the same API as com.codecommit.antixml.StAXParser, but the runtime performance is on the order of 13% slower. The SAX2 event handler used under the surface is part of the public API in the form of com.codecommit.antixml.NodeSeqSAXHandler.

  21. trait Selectable[+A <: Node] extends AnyRef

  22. trait Selector[+A] extends PartialFunction[Node, A]

  23. class StAXParser extends XMLParser

    An XML parser build on top of javax.xml.stream.

    An XML parser build on top of javax.xml.stream. This implements the same API as com.codecommit.antixml.SAXParser, but the runtime performance is on the order of 12% faster.

  24. case class Text(text: String) extends Node with Product with Serializable

    A node containing a single string, representing character data in the XML tree.

    A node containing a single string, representing character data in the XML tree. For example:

    Lorem ipsum &amp; dolor sit amet

    This would result in the following node:

    Text("Lorem ipsum & dolor sit amet")

    Note that reserved characters (as defined by the XML 1.0 spec) are escaped when calling toString. Thus, if you invoke toString on the Text node given in the example above, the result will reverse back into the original text, including the & escape. If you need a text representation which does not escape characters on output, use com.codecommit.antixml.CDATA.

  25. case class UnprefixedNamespaceBinding(_uri: String) extends NamespaceEntry with Product with Serializable

  26. trait XMLConvertable[-A, +B] extends AnyRef

    Typeclass definition for conversions used by the com.codecommit.antixml.Converter pimp.

    Typeclass definition for conversions used by the com.codecommit.antixml.Converter pimp. Note that this type is exactly isomorphic to scala.Function1, right down to the method name (apply). Normally, such a class would in fact extend A => B, rather than simply emulating its interface. However, because most instances of XMLConvertable will be implicit, we cannot blithely extend Function1. To do so would polute the scope with an unexpected proliferation of implicit conversions which would be automatically injected by the Scala compiler, rather than allowing us to tag them explicitly using the convert method.

    See also

    com.codecommit.antixml.Converter

  27. trait XMLParser extends AnyRef

    A trait for objects which construct antixml from XML sources.

  28. class XMLSerializer extends AnyRef

  29. trait Zipper[+A <: Node] extends Group[A] with IndexedSeqLike[A, Zipper[A]]

    Provides an unselect operation which copies this Group's nodes back to the XML tree from which it was derived.See the Anti-XML Overview for a high-level description of this functionality.

    Provides an unselect operation which copies this Group's nodes back to the XML tree from which it was derived.See the Anti-XML Overview for a high-level description of this functionality.

    The Zipper trait augments a com.codecommit.antixml.Group with additional immutable state used to support the unselect method. This state is known as the "zipper context" and is defined by:

    • A reference to another Group, known as the parent of the Zipper.
    • A set of (possibly deep) locations within the parent, known as the holes of the Zipper.
    • A mapping from the top-level indices of the Zipper to its holes, known as the Zipper's replacement map

    Loosely speaking, the unselect method produces an updated version of the parent by replacing its holes with the nodes from the Zipper, as determined by the replacement map. A formal definition of unselect can be found below.

    Certain "modify" operations on a Zipper will propagate the zipper context to the result. The new Zipper's unselect method can then be viewed as applying these modifications back to the parent tree. Currently, the following methods support this propagation of the zipper context:

    • updated, map, flatMap, filter, collect, slice, drop, take, splitAt, and unselect (the latter viewed as a modification of the parent Zipper).

    These operations all provide a natural identification of indices in the new Zipper with the indices they were derived from in the original. This identification is used to lift the replacement map to the new Zipper. The parent and holes of the new Zipper are always the same as those of the original.

    Of course, propagation is only possible if the result can legally be a Zipper. Replacing a Node with a String, for example, will result in an undecorated IndexedSeq because the result violates Zipper's type bounds.

    Node Multiplication and Elision

    A Zipper's replacement map need neither be injective nor surjective. Injectivity can fail due to the action of flatMap, which replaces a node with a sequence of nodes, all of which are associated with the original node's hole. In such cases, unselect will replace the hole with the entire sequence of nodes mapping to it. Surjectivity can fail due to any operation that "removes" items from the Zipper. If a hole is not associated with any Zipper nodes, then unselect will remove that position from the resulting tree.

    Conflicting Holes

    For a given Zipper, a hole, H, is said to be conflicted if the Zipper contains another hole, Hc , contained in the subtree at H. In this case, the Zipper is said to be conflicted at H. A Zipper that does not contain conflicted holes is said to be conflict free. Conflicted holes arise when a selection operator yields both a node and one or more of its descendants. They are of concern because there is no canonical way to specify the behavior of unselect at a conflicted hole. Instead, a com.codecommit.antixml.ZipperMergeStrategy, implicitly provided to unselect, is used to resolve the conflict.

    A default ZipperMergeStrategy has been provided that should suffice for the most common use cases involving conflicted holes. In particular, if modifications to a conflicted element are limited to its top-level properties (name, attributes, etc.), then the default strategy will apply those changes while preserving any modifications made to those descendant nodes also present in the Zipper. However, if the children property of a conflicted element is directly modified, then the default strategy's behavior is formally unspecified. Currently it uses a heuristic algorithm to resolve conflicts, but its details may change in a future release.

    Of the com.codecommit.antixml.Selectable operators, only \\ is capable of producing conflicts. The select, \, and \\! operators always produce conflict-free Zippers.

    Unselection Algorithm

    Let G be a group, and Z be a zipper with G as its parent. For each location, L, in G (top-level or otherwise), we make the following definitions:

    • G(L) is the node in G at location L.
    • children(L) is the sequence of locations that are immediately below L in G.
    • L is a hole if it is in Z's "holes" set.
    • L is above a hole if some descendant of L is a hole.
    • If L is a hole, the direct updates for L is the sequence of nodes given by the inverse of Z's replacement map, in the order defined by Z.
    • For any L, The indirect update for L is just G(L) with its children replaced by children(L).flatMap(pullback).
    • For any L, pullback(L) is the sequence of nodes given by the following recursive definition:
      • If L is not a hole, then pullback(L) is the singleton sequence consisting of the indirect update for L
      • If L is a hole, but is not above a hole, then pullback(L) is the direct updates for L.
      • Otherwise, L is conflicted and pullback(L) is the result of merging its direct updates and its indirect update according to the com.codecommit.antixml.ZipperMergeStrategy provided to unselect.

    Let T be the sequence of top-level locations in G. Then Z.unselect is defined as T.flatMap(pullback).

  30. case class ZipperMergeContext(original: Node, directUpdate: IndexedSeq[(Node, Int)], lastDirectUpdate: Int, indirectUpdate: (Node, Int)) extends Product with Serializable

    Describes the parameters of a merge operation.

    Describes the parameters of a merge operation. See the com.codecommit.antixml.Zipper trait for formal definitions of these parameters.

    Note that a merge operation always occurs at a particular conflicted hole (location) within the parent XML tree. All of the ZipperMergeContext attributes are considered to be "located" at that hole.

    original

     the original Node that was present at the conflicted hole.

    directUpdate

     the direct updates for the hole and their corresponding update times. These are the nodes that explicitly replaced original via modifications made to the Zipper.

    lastDirectUpdate

     the largest update time of any direct update to the hole. If directUpdates is empty, this will indicate the time that the node was removed.

    indirectUpdate

     the indirect update for the hole and its associated update time. This node's descendants contains the results of all the updates made to the descendant holes causing the conflict. It's top-level attributes are the same as those of original

    See also

    com.codecommit.antixml.Zipper, com.codecommit.antixml.ZipperMergeStrategy

  31. trait ZipperMergeStrategy extends AnyRef

    Defines the merge function used to resolve the behavior of Zipper.unselect at conflicted holes..

    Defines the merge function used to resolve the behavior of Zipper.unselect at conflicted holes.. See com.codecommit.antixml.Zipper for more details.

    The companion object contains some predefined strategies, including the default implicit strategy, PreferLatest.

    See also

    com.codecommit.antixml.Zipper, com.codecommit.antixml.ZipperMergeContext

Value Members

  1. val *: Selector[Node]

    Wildcard selector which passes all nodes unmodified.

    Wildcard selector which passes all nodes unmodified. This is analogous to the "_" selector syntax in scala.xml. For example: ns \ * \ "name"

    Definition Classes
    LowPrioritiyImplicits
  2. object Attributes

    Factory companion for the com.codecommit.antixml.Attributes specialized Map.

    Factory companion for the com.codecommit.antixml.Attributes specialized Map. The only method of serious interest in this object is the apply method, which works exactly the same as the apply method on any Map companion object.

  3. object CanBuildFromWithZipper

    Different implicit implementations of com.codecommit.antixml.CanBuildFromWithZipper.

  4. object Elem extends Serializable

  5. object ElemNamespaceUri

  6. object Group

    Factory singleton for Group.

    Factory singleton for Group. This object is primarily used for creating new Group(s) from specified nodes.

  7. object NSRepr

  8. object NamespaceBinding extends Serializable

  9. object NamespaceEntry

  10. object NamespaceUri

  11. object QName extends Serializable

  12. object Selector

  13. object XML extends StAXParser

    The default XML parser instance for the Anti-XML framework.

    The default XML parser instance for the Anti-XML framework. This is really just a convenience instance of com.codecommit.antixml.XMLParser. The default parser (currently) uses the Java StAX framework under the surface, though the parser interface is also 100% compatible with the SAX2 framework (see: com.codecommit.antixml.SAXParser). The StAX implementation is the default primarily for performance reasons.

    It is possible to reuse some of Anti-XML's internal parser infrastructure to parse into Anti-XML trees from alternative parse frameworks, such as HTML parsers (think: TagSoup). This infrastructure is exposed via the com.codecommit.antixml.NodeSeqSAXHandler class. Unlike scala.xml, Anti-XML does not allow extension of its com.codecommit.antixml.Node construction process. Thus, it is not possible to define (or directly parse into) custom com.codecommit.antixml.Node instances. This capability wouldn't make much sense though, since com.codecommit.antixml.Node is sealed. It is not possible to even define custom instances, much less produce them as part of the parse process.

    See also

    com.codecommit.antixml.StAXParser, com.codecommit.antixml.SAXParser

  14. object XMLConvertable extends SecondPrecedenceConvertables

    Contains the built-in explicit conversions into Anti-XML.

    Contains the built-in explicit conversions into Anti-XML. Currently, these conversions only cover types in scala.xml. This may be expanded in future.

    All of the members in this object are implicit, and thus it is rare for a user to need to access them directly. The membership is contrived in such a way that the implicit resolution will use the following precedence order:

    • ElemConvertable
    • TextConvertable
    • EntityRefConvertable
    • NodeConvertable
    • NodeSeqConvertable

    This corresponds with the roughly-intuitive conversion precedence. Thus, if we have a value of type scala.xml.Elem and we invoke the convert method on that value, the result will be of type com.codecommit.antixml.Elem. However, if we take that same value and ascribe it the type of scala.xml.Node, the convert method will return a value of type com.codecommit.antixml.Node. Finally, we can take this same value and ascribe it the even less-specific type of scala.xml.NodeSeq (or even scala.Seq[scala.xml.Node], for that matter). Invoking the convert method on this maximally-widened type will produce a value of type com.codecommit.antixml.Group[com.codecommit.antixml.Node]. Thus, the most specific conversion is chosen in all cases.

  15. object XMLParser

  16. object XMLSerializer

  17. object Zipper

  18. object ZipperMergeStrategy

  19. implicit def namespaceBindingToNsRepr(nb: NamespaceEntry): NSRepr

    Definition Classes
    LowPrioritiyImplicits
  20. implicit def nodeSeqToConverter[A](a: A): Converter[A]

    Pimps the convert method onto any object for which there exists a conversion into Anti-XML.

    Pimps the convert method onto any object for which there exists a conversion into Anti-XML. Note that this conversion is an implicit value, statically enforced and thus shouldn't be the source of any collision issues. It should actually be possible to have another implicit conversion in scope which pimps the convert method without seeing conflicts.

    Definition Classes
    LowPrioritiyImplicits
    See also

    com.codecommit.antixml.XMLConvertable

  21. implicit def stringToNsRepr(s: String): NSRepr

    Definition Classes
    LowPrioritiyImplicits
  22. implicit def stringTupleToQNameTuple(pair: (String, String)): (QName, String)

    Definition Classes
    LowPrioritiyImplicits
  23. val text: Selector[String]

    Non-node selector which finds exclusively com.codecommit.antixml.Text nodes and pulls out their String content.

    Non-node selector which finds exclusively com.codecommit.antixml.Text nodes and pulls out their String content. Unlike most selectors, the result of using this selector is not a com.codecommit.antixml.Group, but a generic scala.collection.Traversable[String]. This selector can be used to emulate the NodeSeq#text method provided by scala.xml. For example: ns \\ text mkString (this is analogous, but not quite equivalent to calling ns.text in scala.xml).

    Definition Classes
    LowPrioritiyImplicits

Inherited from LowPrioritiyImplicits

Inherited from AnyRef

Inherited from Any

Ungrouped