com.codecommit.antixml

Elem

case class Elem (prefix: Option[String], name: String, attrs: Attributes, scope: Map[String, String], children: Group[Node]) 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. For example:

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

This would result in the following node:

Elem(None, "span", Attributes("id" -> "foo", "class" -> "bar"), Map(), Group(Text("Lorem ipsum")))
Source
node.scala
Linear Supertypes
Serializable, Serializable, Product, Equals, Selectable[Elem], Node, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Elem
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. Selectable
  7. Node
  8. AnyRef
  9. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Elem (prefix: Option[String], name: String, attrs: Attributes, scope: Map[String, String], children: Group[Node])

Value Members

  1. def != (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  2. def != (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  3. def ## (): Int

    Attributes
    final
    Definition Classes
    AnyRef → Any
  4. def == (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  5. def == (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  6. def \ (selector: Selector[Node]): Zipper[Node]

    [use case] Performs a shallow-select on the XML tree according to the specified selector function.

    [use case]

    Performs a shallow-select on the XML tree according to the specified selector function. Shallow selection is defined according to the following expression:

    Attributes
    abstract
    Definition Classes
    Selectable
  7. def \ [B, That] (selector: Selector[B])(implicit cbfwz: CanBuildFromWithZipper[Group[Elem], B, That]): That

    Performs a shallow-select on the XML tree according to the specified selector function.

    Performs a shallow-select on the XML tree according to the specified selector function. Shallow selection is defined according to the following expression:

    nodes flatMap {
      case Elem(_, _, children) => children collect selector
      case _ => Group()
    }
    

    In English, this means that a shallow selection works by first selecting only the Elem(s) at the top level and then filtering their children according to the selector. The results of these filtrations are concatenated together, producing a single flattened result.

    Very important: This is not the same as the XPath / operator! (nor does it strive to be) XPath is inconsistent in its selection semantics, varying them slightly depending on whether or not you are selecting from the top level or in the middle of a compound expression. As a result, it is categorically impossible to implement XPath in a combinatorial fashion. Rather than give up on combinators, we chose to give up on XPath. In practice, this "select child Elem(s), then filter their children" behavior tends to be the most useful variant of the XPath selection. The "missed" case here is applying a filter to the top-level set of nodes. This is currently not handled by the API (perhaps in future). For now, if you need this functionality, it's pretty easy to get it using the filter method.

    The results of this function will be a collection of some variety, but the exact type is determined by the selector itself. For example:

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

    The three selection expressions here produce very different results. The first will produce a collection of type Zipper[Elem], the second will produce Zipper[Node], while the third will produce scala.collection.Traversable[scala.String]. This reflects the fact that the selector produced (by implicit conversion) from a String will only filter for nodes of type Elem. However, the * selector will filter for all nodes (as the wildcard symbol would suggest) and thus it must return a collection containing the fully-generic Node. Finally, the text selector specifically pulls out the textual contents of nodes, and thus its results will not be nodes at all, but raw String(s).

    Whenever supported by the resulting collection type, the selection operation will preserve a "backtrace", or an "undo log" of sorts. This backtrace is known as a zipper context. This context makes it possible to operate on the collection resulting from performing a selection, then unselect to rebuild the original collection around it (modulo the changes made). This provides a very clean and powerful way of drilling down into an XML tree, making some changes and then realizing those changes within the context of the full tree. In a sense, it solves the major inconvenience associated with immutable tree structures: the need to manually rebuild the entire ancestry of the tree after making a change somewhere within.

    Definition Classes
    Selectable
    See also

    Zipper

  8. def \\ (selector: Selector[Node]): Zipper[Node]

    [use case] Performs a deep-select on the XML tree according to the specified selector function.

    [use case]

    Performs a deep-select on the XML tree according to the specified selector function. Deep selection is defined according to the following recursion:

    Attributes
    abstract
    Definition Classes
    Selectable
  9. def \\ [B, That] (selector: Selector[B])(implicit cbfwz: CanBuildFromWithZipper[Group[Elem], B, That]): That

    Performs a deep-select on the XML tree according to the specified selector function.

    Performs a deep-select on the XML tree according to the specified selector function. Deep selection is defined according to the following recursion:

    def deep(g: Group[Node]):That =
      g flatMap {n => Group(n).collect(selector) ++ deep(n.children)}
    
    nodes flatMap {n => deep(n.children)}
    

    In English, this means that deep selection is defined simply as a depth-first search through the tree, all the way from the root down to the leaves. Note that the recursion does not short circuit when a result is found. Thus, if a parent node matches the selector as well as one of its children, then both the parent and the child will be returned, with the parent preceeding the child in the results.

    Just as with shallow selection, the very outermost level of the group is not considered in the selection. Thus, deep selection is not exactly the same as the XPath // operator, since // will consider the outermost level, while Anti-XML's deep selection \\ will not.

    Definition Classes
    Selectable
  10. def \\! (selector: Selector[Node]): Zipper[Node]

    [use case] Performs a short-circuiting deep-select on the XML tree according to the specified selector.

    [use case]

    Performs a short-circuiting deep-select on the XML tree according to the specified selector. Short-circuit deep selection is defined according to the following recursion:

    Attributes
    abstract
    Definition Classes
    Selectable
  11. def \\! [B, That] (selector: Selector[B])(implicit cbfwz: CanBuildFromWithZipper[com.codecommit.antixml.Group[_ <: com.codecommit.antixml.Node], B, That]): That

    Performs a short-circuiting deep-select on the XML tree according to the specified selector.

    Performs a short-circuiting deep-select on the XML tree according to the specified selector. Short-circuit deep selection is defined according to the following recursion:

    def deep(g: Group[Node]):That =
      g flatMap {n =>
        if (selector.isDefinedAt(n)) Group(n).collect(selector)
        else deep(n.children)
      }
    
    nodes flatMap {n => deep(n.children)}
    

    Like \\, this performs a depth-first search through the tree. However, any time the selector matches a node, it's children are skipped over rather than being searched. Thus, the result is guaranteed to never contain both a node and one of its descendants.

    Just as with shallow selection, the very outermost level of the group is not considered in the selection.

    Definition Classes
    Selectable
  12. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  13. val attrs : Attributes

  14. def canEqual (arg0: Any): Boolean

    Definition Classes
    Elem → Equals
  15. def canonicalize : Elem

    See the canonicalize method on Group.

  16. val children : Group[Node]

    Returns the children of this node.

    Returns the children of this node. If the node is an Elem, then this method returns the element's children. Otherwise, it returns return an empty Group.

    Definition Classes
    ElemNode
  17. def clone (): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  18. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  19. def equals (arg0: Any): Boolean

    Definition Classes
    Elem → Equals → AnyRef → Any
  20. def finalize (): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  21. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef → Any
  22. val hashCode : Int

    Definition Classes
    Elem → AnyRef → Any
  23. def isInstanceOf [T0] : Boolean

    Attributes
    final
    Definition Classes
    Any
  24. val name : String

  25. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  26. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  27. def notifyAll (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  28. val prefix : Option[String]

  29. def productArity : Int

    Definition Classes
    Elem → Product
  30. def productElement (arg0: Int): Any

    Definition Classes
    Elem → Product
  31. def productIterator : Iterator[Any]

    Definition Classes
    Product
  32. def productPrefix : String

    Definition Classes
    Elem → Product
  33. val scope : Map[String, String]

  34. def select (selector: Selector[Node]): Zipper[Node]

    [use case] Performs a selection on the top-level nodes of this group.

    [use case]

    Performs a selection on the top-level nodes of this group. The nodes returned by this method are exactly the same as the nodes returned by:

    Attributes
    abstract
    Definition Classes
    Selectable
  35. def select [B, That] (selector: Selector[B])(implicit cbfwz: CanBuildFromWithZipper[com.codecommit.antixml.Group[_ <: com.codecommit.antixml.Node], B, That]): That

    Performs a selection on the top-level nodes of this group.

    Performs a selection on the top-level nodes of this group. The nodes returned by this method are exactly the same as the nodes returned by:

    nodes.collect(selector)
    

    However, this method differs from collect in that it can return a Zipper with full unselect functionality. Thus, it is possible to select a subset of a group, operate on that subset, and then call unselect to pull those operations back to the original group.

    Definition Classes
    Selectable
  36. def synchronized [T0] (arg0: ⇒ T0): T0

    Attributes
    final
    Definition Classes
    AnyRef
  37. def toGroup : Group[Elem]

    Definition Classes
    ElemSelectable
  38. def toString (): String

    Definition Classes
    Elem → AnyRef → Any
  39. def toZipper : Zipper[Elem]

    Definition Classes
    Selectable
  40. def wait (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  41. def wait (arg0: Long, arg1: Int): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  42. def wait (arg0: Long): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()

Deprecated Value Members

  1. def productElements : Iterator[Any]

    Definition Classes
    Product
    Annotations
    @deprecated
    Deprecated

    use productIterator instead

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Selectable[Elem]

Inherited from Node

Inherited from AnyRef

Inherited from Any