eu.cdevreeze.yaidom

NodeBuilder

sealed trait NodeBuilder extends Immutable with Serializable

DSL to build Elems (or Documents) without having to pass parent Scopes around. Example:

import NodeBuilder._

elem(
  qname = QName("dbclass:Magazine"),
  attributes = Vector(QName("Month") -> "February", QName("Year") -> "2009"),
  namespaces = Declarations.from("dbclass" -> "http://www.db-class.org"),
  children = Vector(
    elem(
      qname = QName("dbclass:Title"),
      children = Vector(text("Newsweek"))))).build()

The latter expression could also be written as follows:

elem(
qname = QName("dbclass:Magazine"),
attributes = Vector(QName("Month") -> "February", QName("Year") -> "2009"),
namespaces = Declarations.from("dbclass" -> "http://www.db-class.org"),
children = Vector(
  textElem(QName("dbclass:Title"), "Newsweek"))).build()

There is an impedance mismatch between XML's scoping rules (which are top-down, from root to leaves) and "functional trees" (which are built bottom-up, from leaves to root). In the context of the Anti-XML library, Daniel Spiewak explained this impedance mismatch in https://github.com/djspiewak/anti-xml/issues/78. In yaidom, however, this impedance mismatch is far less severe. Yaidom distinguishes between eu.cdevreeze.yaidom.Node and eu.cdevreeze.yaidom.NodeBuilder, and eu.cdevreeze.yaidom.Elem and eu.cdevreeze.yaidom.ElemBuilder in particular. Elems have (fixed, resolved) Scopes, but ElemBuilders do not. Using NodeBuilders, Scope determination is postponed. Only ElemBuilders can have unbound prefixes, but only Elems have (resolved) scopes. Instead of a eu.cdevreeze.yaidom.Scope, an ElemBuilder has a eu.cdevreeze.yaidom.Declarations.

Another reason that the above-mentioned impedance mismatch is less of a problem in practice is that typically the XML trees (as NodeBuilders or directly as Nodes) are built in a top-down manner. The eu.cdevreeze.yaidom.ConverterToDocuments in package eu.cdevreeze.yaidom.convert recursively build Elems in a top-down manner, possibly creating an Elem instance (for each element) twice (first without children, and finally as a copy with children added).

When using NodeBuilders to create a Document, this Document typically contains no "ignorable whitespace". This may cause the Document not to be pretty-printed when using a (default) eu.cdevreeze.yaidom.print.DocumentPrinter to convert the Document to an XML string. See also the classes in package eu.cdevreeze.yaidom.print.

NodeBuilders are serializable. Serialized NodeBuilder instances may well be an interesting storage format for parsed XML stored in a database. Of course, this would be a non-standard format. Moreover, as far as queries are concerned, these columns are mere BLOBs (unless using Java Stored Procedures written in Scala).

Linear Supertypes
Serializable, Serializable, Immutable, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. NodeBuilder
  2. Serializable
  3. Serializable
  4. Immutable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. abstract type NodeType <: Node

Abstract Value Members

  1. abstract def build(parentScope: Scope): NodeType

Concrete Value Members

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

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

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

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

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

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. final def build(): NodeType

    Returns build(Scope.Empty)

  8. def clone(): AnyRef

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

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

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

    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  19. final def toString(): String

    Returns toTreeRepr.

    Returns toTreeRepr.

    Definition Classes
    NodeBuilder → AnyRef → Any
  20. final def toTreeRepr(parentScope: Scope): String

    Returns the tree representation.

    Returns the tree representation. See the corresponding method in eu.cdevreeze.yaidom.Node.

  21. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from Serializable

Inherited from Serializable

Inherited from Immutable

Inherited from AnyRef

Inherited from Any

Ungrouped