Packages

  • package root
    Definition Classes
    root
  • package eu
    Definition Classes
    root
  • package cdevreeze
    Definition Classes
    eu
  • package yaidom

    Yaidom is yet another Scala immutable DOM-like XML API.

    Yaidom is yet another Scala immutable DOM-like XML API. The best known Scala immutable DOM-like API is the standard scala.xml API. It:

    • attempts to offer an XPath-like querying experience, thus somewhat blurring the distinction between nodes and node collections
    • lacks first-class support for XML namespaces
    • has limited (functional) update support

    Yaidom takes a different approach, avoiding XPath-like query support in its query API, and offering good namespace and decent (functional) update support. Yaidom is also characterized by almost mathematical precision and clarity. Still, the API remains practical and pragmatic. In particular, the API user has much configuration control over parsing and serialization, because yaidom exposes the underlying JAXP parsers and serializers, which can be configured by the library user.

    Yaidom chooses its battles. For example, given that DTDs do not know about namespaces, yaidom offers good namespace support, but ignores DTDs entirely. Of course the underlying XML parser may still validate XML against a DTD, if so desired. As another example, yaidom tries to leave the handling of the gory details of XML processing (such as whitespace handling) as much as possible to JAXP (and JAXP parser/serializer configuration). As yet another example, yaidom knows nothing about (XML Schema) types of elements and attributes.

    As mentioned above, yaidom tries to treat basic XML processing with almost mathematical precision, even if this is "incorrect". At the same time, yaidom tries to be useful in practice. For example, yaidom compromises "correctness" in the following ways:

    • Yaidom does not generally consider documents to be nodes (called "document information items" in the XML Infoset), thus introducing fewer constraints on DOM-like node construction
    • Yaidom does not consider attributes to be (non-child) nodes (called "attribute information items" in the XML Infoset), thus introducing fewer constraints on DOM-like node construction
    • Yaidom does not consider namespace declarations to be attributes, thus facilitating a clear theory of namespaces
    • Yaidom tries to keep the order of the attributes (for better round-tripping), although attribute order is irrelevant according to the XML Infoset
    • Very importantly, yaidom clearly distinguishes between qualified names (QNames) and expanded names (ENames), which is essential in facilitating a clear theory of namespaces

    Yaidom, and in particular the eu.cdevreeze.yaidom.core, eu.cdevreeze.yaidom.queryapi, eu.cdevreeze.yaidom.resolved and eu.cdevreeze.yaidom.simple sub-packages, contains the following layers:

    • basic concepts, such as (qualified and expanded) names of elements and attributes (in the core package)
    • the uniform query API traits, to query elements for child, descendant and descendant-or-self elements (in the queryapi package)
    • some of the specific element implementations, mixing in those uniform query API traits (e.g. in the resolved and simple packages)

    It makes sense to read this documentation, because it helps in getting up-to-speed with yaidom.

    Basic concepts

    In real world XML, elements (and sometimes attributes) tend to have names within a certain namespace. There are 2 kinds of names at play here:

    • qualified names: prefixed names, such as book:Title, and unprefixed names, such as Edition
    • expanded names: having a namespace, such as {http://bookstore/book}Title (in James Clark notation), and not having a namespace, such as Edition

    They are represented by immutable classes eu.cdevreeze.yaidom.core.QName and eu.cdevreeze.yaidom.core.EName, respectively.

    Qualified names occur in XML, whereas expanded names do not. Yet qualified names have no meaning on their own. They need to be resolved to expanded names, via the in-scope namespaces. Note that the term "qualified name" is often used for what yaidom (and the Namespaces specification) calls "expanded name", and that most XML APIs do not distinguish between the 2 kinds of names. Yaidom has to clearly make this distinction, in order to model namespaces correctly.

    To resolve qualified names to expanded names, yaidom distinguishes between:

    • namespace declarations
    • in-scope namespaces

    They are represented by immutable classes eu.cdevreeze.yaidom.core.Declarations and eu.cdevreeze.yaidom.core.Scope, respectively.

    Namespace declarations occur in XML, whereas in-scope namespaces do not. The latter are the accumulated effect of the namespace declarations of the element itself, if any, and those in ancestor elements.

    Note: in the code examples below, we assume the following import:

    import eu.cdevreeze.yaidom.core._

    To see the resolution of qualified names in action, consider the following sample XML:

    <book:Bookstore xmlns:book="http://bookstore/book" xmlns:auth="http://bookstore/author">
      <book:Book ISBN="978-0321356680" Price="35" Edition="2">
        <book:Title>Effective Java (2nd Edition)</book:Title>
        <book:Authors>
          <auth:Author>
            <auth:First_Name>Joshua</auth:First_Name>
            <auth:Last_Name>Bloch</auth:Last_Name>
          </auth:Author>
        </book:Authors>
      </book:Book>
      <book:Book ISBN="978-0981531649" Price="35" Edition="2">
        <book:Title>Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition</book:Title>
        <book:Authors>
          <auth:Author>
            <auth:First_Name>Martin</auth:First_Name>
            <auth:Last_Name>Odersky</auth:Last_Name>
          </auth:Author>
          <auth:Author>
            <auth:First_Name>Lex</auth:First_Name>
            <auth:Last_Name>Spoon</auth:Last_Name>
          </auth:Author>
          <auth:Author>
            <auth:First_Name>Bill</auth:First_Name>
            <auth:Last_Name>Venners</auth:Last_Name>
          </auth:Author>
        </book:Authors>
      </book:Book>
    </book:Bookstore>

    Consider the last element with qualified name QName("book:Book"). To resolve this qualified name as expanded name, we need to know the namespaces in scope at that element. To compute the in-scope namespaces, we need to accumulate the namespace declarations of the last book:Book element and of its ancestor element(s), starting with the root element.

    The start Scope is "parent scope" Scope.Empty. Then, in the root element we find namespace declarations:

    Declarations.from("book" -> "http://bookstore/book", "auth" -> "http://bookstore/author")

    This leads to the following namespaces in scope at the root element:

    Scope.Empty.resolve(Declarations.from("book" -> "http://bookstore/book", "auth" -> "http://bookstore/author"))

    which is equal to:

    Scope.from("book" -> "http://bookstore/book", "auth" -> "http://bookstore/author")

    We find no other namespace declarations in the last book:Book element or its ancestor(s), so the computed scope is also the scope of the last book:Book element.

    Then QName("book:Book") is resolved as follows:

    Scope.from("book" -> "http://bookstore/book", "auth" -> "http://bookstore/author").resolveQNameOption(QName("book:Book"))

    which is equal to:

    Some(EName("{http://bookstore/book}Book"))

    This namespace support in yaidom has mathematical rigor. The immutable classes QName, EName, Declarations and Scope have precise definitions, reflected in their implementations, and they obey some interesting properties. For example, if we correctly define Scope operation relativize (along with resolve), we get:

    scope1.resolve(scope1.relativize(scope2)) == scope2

    This may not sound like much, but by getting the basics right, yaidom succeeds in offering first-class support for XML namespaces, without the magic and namespace-related bugs often found in other XML libraries.

    There are 2 other basic concepts in this package, representing paths to elements:

    • path builders
    • paths

    They are represented by immutable classes eu.cdevreeze.yaidom.core.PathBuilder and eu.cdevreeze.yaidom.core.Path, respectively.

    Path builders are like canonical XPath expressions, yet they do not contain the root element itself, and indexing starts with 0 instead of 1.

    For example, the last name of the first author of the last book element has path:

    Path.from(
      EName("{http://bookstore/book}Book") -> 1,
      EName("{http://bookstore/book}Authors") -> 0,
      EName("{http://bookstore/author}Author") -> 0,
      EName("{http://bookstore/author}Last_Name") -> 0
    )

    This path could be written as path builder as follows:

    PathBuilder.from(QName("book:Book") -> 1, QName("book:Authors") -> 0, QName("auth:Author") -> 0, QName("auth:Last_Name") -> 0)

    Using the Scope mentioned earlier, the latter path builder resolves to the path given before that, by invoking method PathBuilder.build(scope). In order for this to work, the Scope must be invertible. That is, there must be a one-to-one correspondence between prefixes ("" for the default namespace) and namespace URIs, because otherwise the index numbers may differ. Also note that the prefixes book and auth in the path builder are arbitrary, and need not match with the prefixes used in the XML tree itself.

    Uniform query API traits

    Yaidom provides a relatively small query API, to query an individual element for collections of child elements, descendant elements or descendant-or-self elements. The resulting collections are immutable Scala collections, that can further be manipulated using the Scala Collections API.

    This query API is uniform, in that different element implementations share (most of) the same query API. It is also element-centric (unlike standard Scala XML).

    For example, consider the XML example given earlier, as a Scala XML literal named bookstore. We can wrap this Scala XML Elem into a yaidom wrapper of type ScalaXmlElem, named bookstoreElem. Then we can query for all books, that is, all descendant-or-self elements with resolved (or expanded) name EName("{http://bookstore/book}Book"), as follows:

    bookstoreElem filterElemsOrSelf (elem => elem.resolvedName == EName("{http://bookstore/book}Book"))

    The result would be an immutable IndexedSeq of ScalaXmlElem instances, holding 2 book elements.

    We could instead have written:

    bookstoreElem.filterElemsOrSelf(EName("{http://bookstore/book}Book"))

    with the same result, due to an implicit conversion from expanded names to element predicates.

    Instead of searching for appropriate descendant-or-self elements, we could have searched for descendant elements only, without altering the result in this case:

    bookstoreElem filterElems (elem => elem.resolvedName == EName("{http://bookstore/book}Book"))

    or:

    bookstoreElem.filterElems(EName("{http://bookstore/book}Book"))

    We could even have searched for appropriate child elements only, without altering the result in this case:

    bookstoreElem filterChildElems (elem => elem.resolvedName == EName("{http://bookstore/book}Book"))

    or:

    bookstoreElem.filterChildElems(EName("{http://bookstore/book}Book"))

    or, knowing that all child elements are books:

    bookstoreElem.findAllChildElems

    We could find all authors of the Scala book as follows:

    for {
      bookElem <- bookstoreElem filterChildElems (elem => elem.resolvedName == EName("{http://bookstore/book}Book"))
      if bookElem.attributeOption(EName("ISBN")).contains("978-0981531649")
      authorElem <- bookElem filterElems (elem => elem.resolvedName == EName("{http://bookstore/author}Author"))
    } yield authorElem

    or:

    for {
      bookElem <- bookstoreElem.filterChildElems(EName("{http://bookstore/book}Book"))
      if bookElem.attributeOption(EName("ISBN")).contains("978-0981531649")
      authorElem <- bookElem.filterElems(EName("{http://bookstore/author}Author"))
    } yield authorElem

    We could even use operator notation, as follows:

    for {
      bookElem <- bookstoreElem \ (elem => elem.resolvedName == EName("{http://bookstore/book}Book"))
      if (bookElem \@ EName("ISBN")).contains("978-0981531649")
      authorElem <- bookElem \\ (elem => elem.resolvedName == EName("{http://bookstore/author}Author"))
    } yield authorElem

    or:

    for {
      bookElem <- bookstoreElem \ EName("{http://bookstore/book}Book")
      if (bookElem \@ EName("ISBN")).contains("978-0981531649")
      authorElem <- bookElem \\ EName("{http://bookstore/author}Author")
    } yield authorElem

    where \\ stands for filterElemsOrSelf.

    There is no explicit support for filtering on the "self" element itself. In the example above, we might want to check if the root element has the expected EName, for instance. That is easy to express using a simple idiom, however. The last example then becomes:

    for {
      bookstoreElem <- Vector(bookstoreElem)
      if bookstoreElem.resolvedName == EName("{http://bookstore/book}Bookstore")
      bookElem <- bookstoreElem \ EName("{http://bookstore/book}Book")
      if (bookElem \@ EName("ISBN")).contains("978-0981531649")
      authorElem <- bookElem \\ EName("{http://bookstore/author}Author")
    } yield authorElem

    Now suppose the same XML is stored in a (org.w3c.dom) DOM tree, wrapped in a DomElem bookstoreElem. Then the same queries would use exactly the same code as above! The result would be a collection of DomElem instances instead of ScalaXmlElem instances, however. There are many more element implementations in yaidom, and they share (most of) the same query API. Therefore this query API is called a uniform query API.

    The last example, using operator notation, looks a bit more "XPath-like". It is more verbose than queries in Scala XML, however, partly because in yaidom these operators cannot be chained. Yet this is with good reason. Yaidom does not blur the distinction between elements and element collections, and therefore does not offer any XPath experience. The small price paid in verbosity is made up for by precision. The yaidom query API traits have very precise definitions of their operations, as can be seen in the corresponding documentation.

    The uniform query API traits turn minimal APIs into richer APIs, where each richer API is defined very precisely in terms of the minimal API. The most important (partly concrete) query API trait is eu.cdevreeze.yaidom.queryapi.ElemLike. It needs to be given a method implementation to query for child elements (not child nodes in general, but just child elements!), and it offers methods to query for some or all child elements, descendant elements, and descendant-or-self elements. That is, the minimal API consists of abstract method findAllChildElems, and it offers methods such as filterChildElems, filterElems and filterElemsOrSelf. This trait has no knowledge about elements at all, other than the fact that elements can have child elements.

    Trait eu.cdevreeze.yaidom.queryapi.HasEName needs minimal knowledge about elements themselves, viz. that elements have a "resolved" (or expanded) name, and "resolved" attributes (mapping attribute expanded names to attribute values). That is, it needs to be given implementations of abstract methods resolvedName and resolvedAttributes, and then offers methods to query for individual attributes or the local name of the element.

    It is important to note that yaidom does not consider namespace declarations to be attributes themselves. Otherwise, there would have been circular dependencies between both concepts, because attributes with namespaces require in-scope namespaces and therefore namespace declarations for resolving the names of these attributes.

    Many traits, such as eu.cdevreeze.yaidom.queryapi.HasEName, are just "capabilities", and need to be combined with trait eu.cdevreeze.yaidom.queryapi.ElemLike in order to offer a useful element querying API.

    Note that trait eu.cdevreeze.yaidom.queryapi.ElemLike only knows about elements, not about other kinds of nodes. Of course the actual element implementations mixing in this query API know about other node types, but that knowledge is outside the uniform query API. Note that the example queries above only use the minimal element knowledge that traits ElemLike and HasEName together have about elements. Therefore the query code can be used unchanged for different element implementations.

    Trait eu.cdevreeze.yaidom.queryapi.IsNavigable is used to navigate to an element given a Path.

    Trait eu.cdevreeze.yaidom.queryapi.UpdatableElemLike (which extends trait IsNavigable) offers functional updates at given paths. Whereas the traits mentioned above know only about elements, this trait knows that elements have some node super-type.

    Instead of functional updates at given paths, elements can also be "transformed" functionally without specifying any paths. This is offered by trait eu.cdevreeze.yaidom.queryapi.TransformableElemLike. The Scala XML and DOM wrappers above do not mix in this trait.

    Three uniform query API levels

    Above, several individual query API traits were mentioned. There are, however, 3 query API levels which are interesting for those who extend yaidom with new element implementations, but also for most users of the yaidom query API. These levels are represented by "combination traits" that combine several of the query API traits mentioned (or not mentioned) above.

    The most basic level is eu.cdevreeze.yaidom.queryapi.ClarkNodes.Elem. It combines traits such as eu.cdevreeze.yaidom.queryapi.ElemApi and eu.cdevreeze.yaidom.queryapi.HasENameApi. Object eu.cdevreeze.yaidom.queryapi.ClarkNodes also contains types for non-element nodes. All element implementations that extend trait ClarkNodes.Elem should have a node hierarchy with all its kinds of nodes extending the appropriate ClarkNodes member type.

    All element implementation directly or indirectly implement the ClarkNodes.Elem trait. The part of the yaidom query API that knows about ElemApi querying and about ENames is the ClarkNodes query API level. It does not know about QNames, in-scope namespaces, ancestor elements, base URIs, etc.

    The next level is eu.cdevreeze.yaidom.queryapi.ScopedNodes.Elem. It extends the ClarkNodes.Elem trait, but offers knowledge about QNames and in-scope namespaces as well. Many element implementations offer at least this query API level. The remarks about non-element nodes above also apply here, and apply below.

    The third level is eu.cdevreeze.yaidom.queryapi.BackingNodes.Elem. It extends the ScopedNodes.Elem trait, but offers knowledge about ancestor elements and document/base URIs as well. This is the level typically used for "backing elements" in "yaidom dialects", thus allowing for multiple "XML backends" to be used behind "yaidom dialects". Yaidom dialects are specific "XML dialect" type-safe yaidom query APIs, mixing in and leveraging trait eu.cdevreeze.yaidom.queryapi.SubtypeAwareElemApi (often in combination with eu.cdevreeze.yaidom.queryapi.ScopedNodes.Elem).

    To get to know the yaidom query API and its 3 levels, it pays off to study the API documentation of traits eu.cdevreeze.yaidom.queryapi.ClarkNodes.Elem, eu.cdevreeze.yaidom.queryapi.ScopedNodes.Elem and eu.cdevreeze.yaidom.queryapi.BackingNodes.Elem.

    Some element implementations

    In package simple there are 2 immutable element implementations, eu.cdevreeze.yaidom.simple.ElemBuilder and eu.cdevreeze.yaidom.simple.Elem. Arguably, ElemBuilder is not an element implementation. Indeed, it does not even offer the ClarkNodes.Elem query API.

    Class eu.cdevreeze.yaidom.simple.Elem is the default element implementation of yaidom. It extends class eu.cdevreeze.yaidom.simple.Node. The latter also has sub-classes for text nodes, comments, entity references and processing instructions. Class eu.cdevreeze.yaidom.simple.Document contains a document Elem, but is not a Node sub-class itself. This node hierarchy offers the ScopedNodes query API, so simple elements offer the ScopedNodes.Elem query API.

    The eu.cdevreeze.yaidom.simple.Elem class has the following characteristics:

    • It is immutable, and thread-safe
    • These elements therefore cannot be queried for their parent elements
    • It mixes in query API trait eu.cdevreeze.yaidom.queryapi.ScopedNodes.Elem, eu.cdevreeze.yaidom.queryapi.UpdatableElemApi and eu.cdevreeze.yaidom.queryapi.TransformableElemApi
    • Besides the element name, attributes and child nodes, it keeps a Scope, but no Declarations
    • This makes it easy to compose these elements, as long as scopes are passed explicitly throughout the element tree
    • Equality is reference equality, because it is hard to come up with a sensible equality for this element class
    • Roundtripping cannot be entirely lossless, but this class does try to retain the attribute order (although irrelevant according to XML Infoset)
    • Packages parse and print offer DocumentParser and DocumentPrinter classes for parsing/serializing these default Elem (and Document) instances

    Creating such Elem trees by hand is a bit cumbersome, partly because scopes have to be passed to each Elem in the tree. The latter is not needed if we use class eu.cdevreeze.yaidom.simple.ElemBuilder to create element trees by hand. When the tree has been fully created as ElemBuilder, invoke method ElemBuilder.build(parentScope) to turn it into an Elem.

    Like their super-classes Node and NodeBuilder, classes Elem and ElemBuilder have very much in common. Both are immutable, easy to compose (ElemBuilder instances even more so), equality is reference equality, etc. The most important differences are as follows:

    • Instead of a Scope, an ElemBuilder contains a Declarations
    • This makes an ElemBuilder easier to compose than an Elem, because no Scope needs to be passed around throughout the tree
    • Class ElemBuilder uses a minimal query API, mixing in almost only traits ElemLike and TransformableElemLike
    • After all, an ElemBuilder neither keeps nor knows about Scopes, so does not know about resolved element/attribute names

    The Effective Java book element in the XML example above could have been written as ElemBuilder (without the inter-element whitespace) as follows:

    import NodeBuilder._
    
    elem(
      qname = QName("book:Book"),
      attributes = Vector(QName("ISBN") -> "978-0321356680", QName("Price") -> "35", QName("Edition") -> "2"),
      children = Vector(
        elem(
          qname = QName("book:Title"),
          children = Vector(
            text("Effective Java (2nd Edition)")
          )
        ),
        elem(
          qname = QName("book:Authors"),
          children = Vector(
            elem(
              qname = QName("auth:Author"),
              children = Vector(
                elem(
                  qname = QName("auth:First_Name"),
                  children = Vector(
                    text("Joshua")
                  )
                ),
                elem(
                  qname = QName("auth:Last_Name"),
                  children = Vector(
                    text("Bloch")
                  )
                )
              )
            )
          )
        )
      )
    )

    This ElemBuilder (say, eb) lacks namespace declarations for prefixes book and auth. So, the following returns false:

    eb.canBuild(Scope.Empty)

    while the following returns true:

    eb.canBuild(Scope.from("book" -> "http://bookstore/book", "auth" -> "http://bookstore/author"))

    Indeed,

    eb.build(Scope.from("book" -> "http://bookstore/book", "auth" -> "http://bookstore/author"))

    returns the element tree as Elem.

    Note that the distinction between ElemBuilder and Elem "solves" the mismatch that immutable ("functional") element trees are constructed in a bottom-up manner, while namespace scoping works in a top-down manner. (See also Anti-XML issue 78, in https://github.com/djspiewak/anti-xml/issues/78).

    There are many more element implementations in yaidom, most of them in sub-packages of this package. Yaidom is extensible in that new element implementations can be invented, for example elements that are better "roundtrippable" (at the expense of "composability"), or yaidom wrappers around other DOM-like APIs (such as XOM or JDOM2). The current element implementations in yaidom are for example:

    • Immutable class eu.cdevreeze.yaidom.simple.Elem, the default (immutable) element implementation. See above.
    • Immutable class eu.cdevreeze.yaidom.simple.ElemBuilder for creating an Elem by hand. See above.
    • Immutable class eu.cdevreeze.yaidom.resolved.Elem, which takes namespace prefixes out of the equation, and therefore makes useful (namespace-aware) equality comparisons feasible. It offers the ClarkNodes.Elem query API (as well as update/transformation support).
    • Immutable class eu.cdevreeze.yaidom.indexed.Elem, which offers views on default Elems that know the ancestry of each element. It offers the BackingNodes.Elem query API, so knows its ancestry, despite being immutable! This element implementation is handy for querying XML schemas, for example, because in schemas the ancestry of queried elements typically matters.

    One yaidom wrapper that is very useful is a Saxon tiny tree yaidom wrapper, namely SaxonElem (JVM-only). Like "indexed elements", it offers all of the BackingNodes.Elem query API. This element implementation is very efficient, especially in memory footprint (when using the default tree model, namely tiny trees). It is therefore the most attractive element implementation to use in "enterprise" production code, but only on the JVM. In combination with Saxon-EE (instead of Saxon-HE) the underlying Saxon NodeInfo objects can even carry interesting type information.

    For ad-hoc element creation, consider using "resolved" elements. They are easy to create, because there is no need to worry about namespace prefixes. Once created, they can be converted to "simple" elements, given an appropriate Scope (without default namespace).

    Packages and dependencies

    Yaidom has the following packages, and layering between packages (mentioning the lowest layers first):

    • Package eu.cdevreeze.yaidom.core, with the core concepts described above. It depends on no other yaidom packages.
    • Package eu.cdevreeze.yaidom.queryapi, with the query API traits described above. It only depends on the core package.
    • Package eu.cdevreeze.yaidom.resolved, with a minimal "James Clark" element implementation. It only depends on the core and queryapi packages.
    • Package eu.cdevreeze.yaidom.simple, with the default element implementation described above. It only depends on the core and queryapi packages.
    • Package eu.cdevreeze.yaidom.indexed, supporting "indexed" elements. It only depends on the core, queryapi and simple packages.
    • Package convert. It contains conversions between default yaidom nodes on the one hand and DOM, Scala XML, etc. on the other hand. The convert package depends on the yaidom core, queryapi, resolved and simple packages.
    • Package eu.cdevreeze.yaidom.saxon, with the Saxon wrapper element implementation described above. It only depends on the core, queryapi and convert packages.
    • Packages eu.cdevreeze.yaidom.parse and eu.cdevreeze.yaidom.print, for parsing/printing Elems. They depend on the packages mentioned above, except for indexed and saxon.
    • The other packages (except utils), such as dom and scalaxml. They depend on (some of) the packages mentioned above, but not on each other.
    • Package eu.cdevreeze.yaidom.utils, which depends on all the packages above.

    Indeed, all yaidom package dependencies are uni-directional.

    Notes on performance

    Yaidom can be quite memory-hungry. One particular cause of that is the possible creation of very many duplicate EName and QName instances. This can be the case while parsing XML into yaidom documents, or while querying yaidom element trees.

    The user of the library can reduce memory consumption to a large extent, and yaidom facilitates that.

    As for querying, prefer:

    import HasENameApi._
    
    bookstoreElem filterElemsOrSelf withEName("http://bookstore/book", "Book")

    to:

    bookstoreElem.filterElemsOrSelf(EName("http://bookstore/book", "Book"))

    to avoid unnecessary (large scale) EName object creation.

    To reduce the memory footprint of parsed XML trees, see eu.cdevreeze.yaidom.core.ENameProvider and eu.cdevreeze.yaidom.core.QNameProvider.

    For example, during the startup phase of an application, we could set the global ENameProvider as follows:

    ENameProvider.globalENameProvider.become(new ENameProvider.ENameProviderUsingImmutableCache(knownENames))

    Note that the global ENameProvider or QNameProvider can typically be configured rather late during development, but the memory cost savings can be substantial. Also note that the global ENameProvider or QNameProvider can be used implicitly in application code, by writing:

    bookstoreElem filterElemsOrSelf getEName("http://bookstore/book", "Book")

    using an implicit ENameProvider, whose members are in scope. Still, for querying the first alternative using withEName is better, but there are likely many scenarios in yaidom client code where an implicit ENameProvider or QNameProvider makes sense.

    The bottom line is that yaidom can be configured to be far less memory-hungry, and that yaidom client code can also take some responsibility in reducing memory usage. Again, the Saxon wrapper implementation is an excellent and efficient choice (but only on the JVM).

    Definition Classes
    cdevreeze
  • package resolved

    This package contains element representations that can be compared for (some notion of "value") equality, unlike normal yaidom nodes.

    This package contains element representations that can be compared for (some notion of "value") equality, unlike normal yaidom nodes. That notion of equality is simple to understand, but "naive". The user is of the API must take control over what is compared for equality.

    See eu.cdevreeze.yaidom.resolved.Node for why this package is named resolved.

    The most important difference with normal Elems is that qualified names do not occur, but only expanded (element and attribute) names. This reminds of James Clark notation for XML trees and expanded names, where qualified names are absent.

    Moreover, the only nodes in this package are element and text nodes.

    Below follows a simple example query, using the uniform query API:

    // Note the import of package resolved, and not of its members. That is indeed a best practice!
    import eu.cdevreeze.yaidom.resolved
    
    val resolvedBookstoreElem = resolved.Elem.from(bookstoreElem)
    
    val scalaBookAuthors =
      for {
        bookElem <- resolvedBookstoreElem \ EName("{http://bookstore/book}Book")
        if (bookElem \@ EName("ISBN")).contains("978-0981531649")
        authorElem <- bookElem \\ EName("{http://bookstore/author}Author")
      } yield authorElem

    The query for Scala book authors would have been exactly the same if normal Elems had been used instead of resolved.Elems (replacing resolvedBookstoreElem by bookstoreElem)!

    Definition Classes
    yaidom
  • Elem
  • Node
  • Text

final case class Elem(resolvedName: EName, resolvedAttributes: Map[EName, String], children: IndexedSeq[Node]) extends Node with queryapi.ClarkNodes.Elem with ClarkElemLike with UpdatableElemLike with TransformableElemLike with Product with Serializable

Element as abstract data type. It contains only expanded names, not qualified names. This reminds of James Clark notation for XML trees and expanded names, where qualified names are absent.

See the documentation of the mixed-in query API trait(s) for more details on the uniform query API offered by this class.

Namespace declarations (and undeclarations) are not considered attributes in this API, just like in the rest of yaidom.

To illustrate equality comparisons in action, consider the following example yaidom Elem, named schemaElem1:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://book" elementFormDefault="qualified">
  <xsd:element name="book">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="isbn" type="xsd:string" />
        <xsd:element name="title" type="xsd:string" />
        <xsd:element name="authors" type="xsd:string" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Now consider the following equivalent yaidom Elem, named schemaElem2, differing only in namespace prefixes, and in indentation:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://book" elementFormDefault="qualified">
    <xs:element name="book">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="isbn" type="xs:string" />
                <xs:element name="title" type="xs:string" />
                <xs:element name="authors" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

These 2 XML trees can be considered equal, if we take indentation and namespace prefixes out of the equation. Note that namespace prefixes also occur in the "type" attributes! The following equality comparison returns true:

def replaceTypeAttributes(elem: Elem): Elem = {
  elem transformElemsOrSelf { e =>
    e.plusAttributeOption(QName("type"), e.attributeAsResolvedQNameOption(EName("type")).map(_.toString))
  }
}

resolved.Elem.from(replaceTypeAttributes(schemaElem1)).removeAllInterElementWhitespace ==
  resolved.Elem.from(replaceTypeAttributes(schemaElem2)).removeAllInterElementWhitespace
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Elem
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. TransformableElemLike
  7. TransformableElemApi
  8. UpdatableElemLike
  9. UpdatableElemApi
  10. ClarkElemLike
  11. HasText
  12. HasEName
  13. IsNavigable
  14. ElemLike
  15. Elem
  16. HasChildNodesApi
  17. AnyElemNodeApi
  18. ClarkElemApi
  19. HasTextApi
  20. HasENameApi
  21. IsNavigableApi
  22. ElemApi
  23. AnyElemApi
  24. Elem
  25. CanBeDocumentChild
  26. CanBeDocumentChild
  27. Node
  28. Immutable
  29. Node
  30. Node
  31. AnyRef
  32. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Elem(resolvedName: EName, resolvedAttributes: Map[EName, String], children: IndexedSeq[Node])

Type Members

  1. type ThisElem = Elem

    The element type itself.

    The element type itself. It must be restricted to a sub-type of the query API trait in question.

    Concrete element classes will restrict this type to that element class itself.

    Definition Classes
    ElemTransformableElemLikeTransformableElemApiUpdatableElemLikeUpdatableElemApiClarkElemLikeIsNavigableElemLikeElemHasChildNodesApiClarkElemApiIsNavigableApiElemApiAnyElemApi
  2. type ThisNode = Node

    The node type, that is a super-type of the element type, but also of corresponding text node types etc.

    The node type, that is a super-type of the element type, but also of corresponding text node types etc.

    Definition Classes
    ElemElemAnyElemNodeApi

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def \(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]

    Shorthand for filterChildElems(p).

    Shorthand for filterChildElems(p). Use this shorthand only if the predicate is a short expression.

    Definition Classes
    ElemLikeElemApi
  5. final def \@(expandedName: EName): Option[String]

    Shorthand for attributeOption(expandedName).

    Shorthand for attributeOption(expandedName).

    Definition Classes
    HasENameHasENameApi
  6. final def \\(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]

    Shorthand for filterElemsOrSelf(p).

    Shorthand for filterElemsOrSelf(p). Use this shorthand only if the predicate is a short expression.

    Definition Classes
    ElemLikeElemApi
  7. final def \\!(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]

    Shorthand for findTopmostElemsOrSelf(p).

    Shorthand for findTopmostElemsOrSelf(p). Use this shorthand only if the predicate is a short expression.

    Definition Classes
    ElemLikeElemApi
  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. final def attribute(expandedName: EName): String

    Returns the value of the attribute with the given expanded name, and throws an exception otherwise.

    Returns the value of the attribute with the given expanded name, and throws an exception otherwise.

    Definition Classes
    HasENameHasENameApi
  10. final def attributeOption(expandedName: EName): Option[String]

    Returns the value of the attribute with the given expanded name, if any, wrapped in an Option.

    Returns the value of the attribute with the given expanded name, if any, wrapped in an Option.

    Definition Classes
    HasENameHasENameApi
  11. final def childNodeIndex(pathEntry: Entry): Int

    Finds the child node index of the given path entry, or -1 if not found.

    Finds the child node index of the given path entry, or -1 if not found. More precisely, returns:

    collectChildNodeIndexes(Set(pathEntry)).getOrElse(pathEntry, -1)
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  12. val children: IndexedSeq[Node]

    Returns the child nodes of this element, in the correct order

    Returns the child nodes of this element, in the correct order

    Definition Classes
    ElemUpdatableElemLikeUpdatableElemApiHasChildNodesApi
  13. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  14. def coalesceAllAdjacentText: Elem

    Returns a copy where adjacent text nodes have been combined into one text node, throughout the node tree

  15. def coalesceAllAdjacentTextAndPostprocess(f: (Text) ⇒ Text): Elem

    Returns a copy where adjacent text nodes have been combined into one text node, throughout the node tree.

    Returns a copy where adjacent text nodes have been combined into one text node, throughout the node tree. After combining the adjacent text nodes, all text nodes are transformed by calling the passed function.

  16. def coalesceAndNormalizeAllText: Elem

    Returns a copy where adjacent text nodes have been combined into one text node, and where all text is normalized, throughout the node tree.

    Returns a copy where adjacent text nodes have been combined into one text node, and where all text is normalized, throughout the node tree. Same as calling coalesceAllAdjacentText followed by normalizeAllText, but more efficient.

  17. def collectChildNodeIndexes(pathEntries: Set[Entry]): Map[Entry, Int]

    Filters the child elements with the given path entries, and returns a Map from the path entries of those filtered elements to the child node indexes.

    Filters the child elements with the given path entries, and returns a Map from the path entries of those filtered elements to the child node indexes. The result Map has no entries for path entries that cannot be resolved. This method should be fast, especially if the passed path entry set is small.

    Definition Classes
    ElemUpdatableElemLikeUpdatableElemApi
  18. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  19. final def filterChildElems(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]

    Returns the child elements obeying the given predicate.

    Returns the child elements obeying the given predicate. This method could be defined as:

    def filterChildElems(p: ThisElem => Boolean): immutable.IndexedSeq[ThisElem] =
      this.findAllChildElems.filter(p)
    Definition Classes
    ElemLikeElemApi
  20. final def filterElems(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]

    Returns the descendant elements obeying the given predicate, in document order.

    Returns the descendant elements obeying the given predicate, in document order. This method could be defined as:

    this.findAllChildElems flatMap (_.filterElemsOrSelf(p))
    Definition Classes
    ElemLikeElemApi
  21. final def filterElemsOrSelf(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]

    Returns the descendant-or-self elements obeying the given predicate, in document order.

    Returns the descendant-or-self elements obeying the given predicate, in document order. This method could be defined as:

    def filterElemsOrSelf(p: ThisElem => Boolean): immutable.IndexedSeq[ThisElem] =
      Vector(this).filter(p) ++ (this.findAllChildElems flatMap (_.filterElemsOrSelf(p)))

    It can be proven that the result is equivalent to findAllElemsOrSelf filter p.

    Definition Classes
    ElemLikeElemApi
  22. def filteringAttributes(p: (EName, String) ⇒ Boolean): Elem
  23. def filteringChildren(p: (Node) ⇒ Boolean): Elem
  24. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  25. def findAllChildElems: IndexedSeq[Elem]

    Returns the element children

    Returns the element children

    Definition Classes
    ElemElemLikeElemApi
  26. final def findAllChildElemsWithPathEntries: IndexedSeq[(ThisElem, Entry)]

    Returns all child elements paired with their path entries.

    Returns all child elements paired with their path entries.

    This method is final, so more efficient implementations for sub-types are not supported. This implementation is only efficient if finding all child elements as well as computing their resolved names is efficient. That is not the case for DOM wrappers or Scala XML Elem wrappers (due to their expensive Scope computations). On the other hand, those wrapper element implementations are convenient, but not intended for heavy use in production. Hence, this method should typically be fast enough.

    Definition Classes
    ClarkElemLikeIsNavigableIsNavigableApi
  27. final def findAllElems: IndexedSeq[ThisElem]

    Returns all descendant elements (not including this element), in document order.

    Returns all descendant elements (not including this element), in document order. This method could be defined as filterElems { e => true }. Equivalent to findAllElemsOrSelf.drop(1).

    Definition Classes
    ElemLikeElemApi
  28. final def findAllElemsOrSelf: IndexedSeq[ThisElem]

    Returns this element followed by all descendant elements (that is, the descendant-or-self elements), in document order.

    Returns this element followed by all descendant elements (that is, the descendant-or-self elements), in document order. This method could be defined as filterElemsOrSelf { e => true }.

    Definition Classes
    ElemLikeElemApi
  29. final def findAttributeByLocalName(localName: String): Option[String]

    Returns the first found attribute value of an attribute with the given local name, if any, wrapped in an Option.

    Returns the first found attribute value of an attribute with the given local name, if any, wrapped in an Option. Because of differing namespaces, it is possible that more than one such attribute exists, although this is not often the case.

    Definition Classes
    HasENameHasENameApi
  30. final def findChildElem(p: (ThisElem) ⇒ Boolean): Option[ThisElem]

    Returns the first found child element obeying the given predicate, if any, wrapped in an Option.

    Returns the first found child element obeying the given predicate, if any, wrapped in an Option. This method could be defined as filterChildElems(p).headOption.

    Definition Classes
    ElemLikeElemApi
  31. final def findChildElemByPathEntry(entry: Entry): Option[ThisElem]

    Finds the child element with the given Path.Entry (where this element is the root), if any, wrapped in an Option.

    Finds the child element with the given Path.Entry (where this element is the root), if any, wrapped in an Option.

    This method is final, so more efficient implementations for sub-types are not supported. This implementation is only efficient if finding all child elements as well as computing their resolved names is efficient. That is not the case for DOM wrappers or Scala XML Elem wrappers (due to their expensive Scope computations). On the other hand, those wrapper element implementations are convenient, but not intended for heavy use in production. Hence, this method should typically be fast enough.

    Definition Classes
    ClarkElemLikeIsNavigableIsNavigableApi
  32. final def findElem(p: (ThisElem) ⇒ Boolean): Option[ThisElem]

    Returns the first found (topmost) descendant element obeying the given predicate, if any, wrapped in an Option.

    Returns the first found (topmost) descendant element obeying the given predicate, if any, wrapped in an Option. This method could be defined as filterElems(p).headOption.

    Definition Classes
    ElemLikeElemApi
  33. final def findElemOrSelf(p: (ThisElem) ⇒ Boolean): Option[ThisElem]

    Returns the first found (topmost) descendant-or-self element obeying the given predicate, if any, wrapped in an Option.

    Returns the first found (topmost) descendant-or-self element obeying the given predicate, if any, wrapped in an Option. This method could be defined as filterElemsOrSelf(p).headOption.

    Definition Classes
    ElemLikeElemApi
  34. final def findElemOrSelfByPath(path: Path): Option[ThisElem]

    Finds the element with the given Path (where this element is the root), if any, wrapped in an Option.

    Finds the element with the given Path (where this element is the root), if any, wrapped in an Option.

    That is, returns:

    findReverseAncestryOrSelfByPath(path).map(_.last)

    Note that for each non-empty Path, we have:

    findElemOrSelfByPath(path) ==
      findChildElemByPathEntry(path.firstEntry).
        flatMap(_.findElemOrSelfByPath(path.withoutFirstEntry))
    Definition Classes
    IsNavigableIsNavigableApi
  35. final def findReverseAncestryOrSelfByPath(path: Path): Option[IndexedSeq[ThisElem]]

    Finds the reversed ancestry-or-self of the element with the given Path (where this element is the root), wrapped in an Option.

    Finds the reversed ancestry-or-self of the element with the given Path (where this element is the root), wrapped in an Option. None is returned if no element can be found at the given Path.

    Hence, the resulting element collection, if any, starts with this element and ends with the element at the given Path, relative to this element.

    This method comes in handy for (efficiently) computing base URIs, where the (reverse) ancestry-or-self is needed as input.

    Definition Classes
    IsNavigableIsNavigableApi
  36. final def findTopmostElems(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]

    Returns the descendant elements obeying the given predicate that have no ancestor obeying the predicate.

    Returns the descendant elements obeying the given predicate that have no ancestor obeying the predicate. This method could be defined as:

    this.findAllChildElems flatMap (_.findTopmostElemsOrSelf(p))
    Definition Classes
    ElemLikeElemApi
  37. final def findTopmostElemsOrSelf(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]

    Returns the descendant-or-self elements obeying the given predicate, such that no ancestor obeys the predicate.

    Returns the descendant-or-self elements obeying the given predicate, such that no ancestor obeys the predicate. This method could be defined as:

    def findTopmostElemsOrSelf(p: ThisElem => Boolean): immutable.IndexedSeq[ThisElem] =
      if (p(this)) Vector(this)
      else (this.findAllChildElems flatMap (_.findTopmostElemsOrSelf(p)))
    Definition Classes
    ElemLikeElemApi
  38. final def getChildElem(p: (ThisElem) ⇒ Boolean): ThisElem

    Returns the single child element obeying the given predicate, and throws an exception otherwise.

    Returns the single child element obeying the given predicate, and throws an exception otherwise. This method could be defined as findChildElem(p).get.

    Definition Classes
    ElemLikeElemApi
  39. final def getChildElemByPathEntry(entry: Entry): ThisElem

    Returns (the equivalent of) findChildElemByPathEntry(entry).get

    Returns (the equivalent of) findChildElemByPathEntry(entry).get

    Definition Classes
    IsNavigableIsNavigableApi
  40. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  41. final def getElemOrSelfByPath(path: Path): ThisElem

    Returns (the equivalent of) findElemOrSelfByPath(path).get

    Returns (the equivalent of) findElemOrSelfByPath(path).get

    Definition Classes
    IsNavigableIsNavigableApi
  42. final def getReverseAncestryOrSelfByPath(path: Path): IndexedSeq[ThisElem]

    Returns (the equivalent of) findReverseAncestryOrSelfByPath(path).get

    Returns (the equivalent of) findReverseAncestryOrSelfByPath(path).get

    Definition Classes
    IsNavigableIsNavigableApi
  43. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  44. final def localName: String

    The local name, that is, the local part of the EName

    The local name, that is, the local part of the EName

    Definition Classes
    HasENameHasENameApi
  45. def minusAttribute(attributeName: EName): Elem

    Functionally removes the given attribute, if present.

  46. final def minusChild(index: Int): ThisElem

    Returns a copy in which the child at the given position (0-based) has been removed.

    Returns a copy in which the child at the given position (0-based) has been removed. Throws an exception if index >= children.size.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  47. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  48. def normalizeAllText: Elem

    Returns a copy where text nodes have been normalized, throughout the node tree.

    Returns a copy where text nodes have been normalized, throughout the node tree. Note that it makes little sense to call this method before coalesceAllAdjacentText.

  49. final def normalizedText: String

    Returns XmlStringUtils.normalizeString(text).

    Returns XmlStringUtils.normalizeString(text).

    Definition Classes
    HasTextHasTextApi
  50. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  51. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  52. def plusAttribute(attributeName: EName, attributeValue: String): Elem

    Functionally adds or updates the given attribute.

  53. def plusAttributeOption(attributeName: EName, attributeValueOption: Option[String]): Elem

    Functionally adds or updates the given attribute, if a value is given.

    Functionally adds or updates the given attribute, if a value is given. That is, returns if (attributeValueOption.isEmpty) thisElem else plusAttribute(attributeName, attributeValueOption.get).

  54. final def plusChild(child: ThisNode): ThisElem

    Returns a copy in which the given child has been inserted at the end

    Returns a copy in which the given child has been inserted at the end

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  55. final def plusChild(index: Int, child: ThisNode): ThisElem

    Returns a copy in which the given child has been inserted at the given position (0-based).

    Returns a copy in which the given child has been inserted at the given position (0-based). If index == children.size, adds the element at the end. If index > children.size, throws an exception.

    Afterwards, the resulting element indeed has the given child at position index (0-based).

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  56. final def plusChildOption(childOption: Option[ThisNode]): ThisElem

    Returns a copy in which the given child, if any, has been inserted at the end.

    Returns a copy in which the given child, if any, has been inserted at the end. That is, returns plusChild(childOption.get) if the given optional child element is non-empty.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  57. final def plusChildOption(index: Int, childOption: Option[ThisNode]): ThisElem

    Returns a copy in which the given child, if any, has been inserted at the given position (0-based).

    Returns a copy in which the given child, if any, has been inserted at the given position (0-based). That is, returns plusChild(index, childOption.get) if the given optional child element is non-empty.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  58. final def plusChildren(childSeq: IndexedSeq[ThisNode]): ThisElem

    Returns a copy in which the given children have been inserted at the end

    Returns a copy in which the given children have been inserted at the end

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  59. def removeAllInterElementWhitespace: Elem

    Returns a copy where inter-element whitespace has been removed, throughout the node tree.

    Returns a copy where inter-element whitespace has been removed, throughout the node tree.

    That is, for each descendant-or-self element determines if it has at least one child element and no non-whitespace text child nodes, and if so, removes all (whitespace) text children.

    This method is useful if it is known that whitespace around element nodes is used for formatting purposes, and (in the absence of an XML Schema or DTD) can therefore be treated as "ignorable whitespace". In the case of "mixed content" (if text around element nodes is not all whitespace), this method will not remove any text children of the parent element.

    XML space attributes (xml:space) are not respected by this method. If such whitespace preservation functionality is needed, it can be written as a transformation where for specific elements this method is not called.

  60. val resolvedAttributes: Map[EName, String]

    The resolved attributes of the element as mapping from ENames to values

    The resolved attributes of the element as mapping from ENames to values

    Definition Classes
    ElemHasENameApi
  61. val resolvedName: EName

    The EName of the element

    The EName of the element

    Definition Classes
    ElemHasENameApi
  62. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  63. def text: String

    Returns the concatenation of the texts of text children, including whitespace.

    Returns the concatenation of the texts of text children, including whitespace. Non-text children are ignored. If there are no text children, the empty string is returned.

    Definition Classes
    ElemHasTextApi
  64. def textChildren: IndexedSeq[Text]

    Returns the text children

  65. def thisElem: ThisElem

    This element itself.

    This element itself.

    Definition Classes
    ElemAnyElemApi
  66. def transformAllText(f: (Text) ⇒ Text): Elem

    Returns a copy where text nodes have been transformed, throughout the node tree.

  67. def transformChildElems(f: (Elem) ⇒ Elem): Elem

    Returns the same element, except that child elements have been replaced by applying the given function.

    Returns the same element, except that child elements have been replaced by applying the given function. Non-element child nodes occur in the result element unaltered.

    That is, returns the equivalent of:

    val newChildren =
      children map {
        case e: E => f(e)
        case n: N => n
      }
    withChildren(newChildren)
    Definition Classes
    ElemTransformableElemLikeTransformableElemApi
  68. def transformChildElemsToNodeSeq(f: (Elem) ⇒ IndexedSeq[Node]): Elem

    Returns the same element, except that child elements have been replaced by applying the given function.

    Returns the same element, except that child elements have been replaced by applying the given function. Non-element child nodes occur in the result element unaltered.

    That is, returns the equivalent of:

    val newChildren =
      children flatMap {
        case e: E => f(e)
        case n: N => Vector(n)
      }
    withChildren(newChildren)
    Definition Classes
    ElemTransformableElemLikeTransformableElemApi
  69. final def transformElems(f: (ThisElem) ⇒ ThisElem): ThisElem

    Transforms the element by applying the given function to all its descendant elements, in a bottom-up manner.

    Transforms the element by applying the given function to all its descendant elements, in a bottom-up manner.

    That is, returns the equivalent of:

    transformChildElems (e => e.transformElemsOrSelf(f))
    Definition Classes
    TransformableElemLikeTransformableElemApi
  70. final def transformElemsOrSelf(f: (ThisElem) ⇒ ThisElem): ThisElem

    Transforms the element by applying the given function to all its descendant-or-self elements, in a bottom-up manner.

    Transforms the element by applying the given function to all its descendant-or-self elements, in a bottom-up manner.

    That is, returns the equivalent of:

    f(transformChildElems (e => e.transformElemsOrSelf(f)))

    In other words, returns the equivalent of:

    f(transformElems(f))
    Definition Classes
    TransformableElemLikeTransformableElemApi
  71. final def transformElemsOrSelfToNodeSeq(f: (ThisElem) ⇒ IndexedSeq[ThisNode]): IndexedSeq[ThisNode]

    Transforms each descendant element to a node sequence by applying the given function to all its descendant-or-self elements, in a bottom-up manner.

    Transforms each descendant element to a node sequence by applying the given function to all its descendant-or-self elements, in a bottom-up manner.

    That is, returns the equivalent of:

    f(transformChildElemsToNodeSeq(e => e.transformElemsOrSelfToNodeSeq(f)))

    In other words, returns the equivalent of:

    f(transformElemsToNodeSeq(f))
    Definition Classes
    TransformableElemLikeTransformableElemApi
  72. final def transformElemsToNodeSeq(f: (ThisElem) ⇒ IndexedSeq[ThisNode]): ThisElem

    Transforms each descendant element to a node sequence by applying the given function to all its descendant elements, in a bottom-up manner.

    Transforms each descendant element to a node sequence by applying the given function to all its descendant elements, in a bottom-up manner. The function is not applied to this element itself.

    That is, returns the equivalent of:

    transformChildElemsToNodeSeq(e => e.transformElemsOrSelfToNodeSeq(f))

    It is equivalent to the following expression:

    transformElemsOrSelf { e => e.transformChildElemsToNodeSeq(che => f(che)) }
    Definition Classes
    TransformableElemLikeTransformableElemApi
  73. final def trimmedText: String

    Returns text.trim.

    Returns text.trim.

    Definition Classes
    HasTextHasTextApi
  74. final def updateChildElem(pathEntry: Entry, newElem: ThisElem): ThisElem

    Returns updateChildElem(pathEntry) { e => newElem }

    Returns updateChildElem(pathEntry) { e => newElem }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  75. final def updateChildElem(pathEntry: Entry)(f: (ThisElem) ⇒ ThisElem): ThisElem

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).

    It can be defined as follows:

    updateChildElems(Set(pathEntry)) { case (che, pe) => f(che) }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  76. final def updateChildElemWithNodeSeq(pathEntry: Entry, newNodes: IndexedSeq[ThisNode]): ThisElem

    Returns updateChildElemWithNodeSeq(pathEntry) { e => newNodes }

    Returns updateChildElemWithNodeSeq(pathEntry) { e => newNodes }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  77. final def updateChildElemWithNodeSeq(pathEntry: Entry)(f: (ThisElem) ⇒ IndexedSeq[ThisNode]): ThisElem

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).

    It can be defined as follows:

    updateChildElemsWithNodeSeq(Set(pathEntry)) { case (che, pe) => f(che) }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  78. final def updateChildElems(f: (ThisElem, Entry) ⇒ Option[ThisElem]): ThisElem

    Invokes updateChildElems, passing the path entries for which the passed function is defined.

    Invokes updateChildElems, passing the path entries for which the passed function is defined. It is equivalent to:

    val editsByPathEntries: Map[Path.Entry, ThisElem] =
      findAllChildElemsWithPathEntries.flatMap({ case (che, pe) =>
        f(che, pe).map(newE => (pe, newE)) }).toMap
    
    updateChildElems(editsByPathEntries.keySet) { case (che, pe) =>
      editsByPathEntries.getOrElse(pe, che) }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  79. final def updateChildElems(pathEntries: Set[Entry])(f: (ThisElem, Entry) ⇒ ThisElem): ThisElem

    Updates the child elements with the given path entries, applying the passed update function.

    Updates the child elements with the given path entries, applying the passed update function.

    That is, returns the equivalent of:

    updateChildElemsWithNodeSeq(pathEntries) { case (che, pe) => Vector(f(che, pe)) }

    If the set of path entries is small, this method is rather efficient.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  80. final def updateChildElemsWithNodeSeq(f: (ThisElem, Entry) ⇒ Option[IndexedSeq[ThisNode]]): ThisElem

    Invokes updateChildElemsWithNodeSeq, passing the path entries for which the passed function is defined.

    Invokes updateChildElemsWithNodeSeq, passing the path entries for which the passed function is defined. It is equivalent to:

    val editsByPathEntries: Map[Path.Entry, immutable.IndexedSeq[ThisNode]] =
      findAllChildElemsWithPathEntries.flatMap({ case (che, pe) =>
        f(che, pe).map(newNodes => (pe, newNodes)) }).toMap
    
    updateChildElemsWithNodeSeq(editsByPathEntries.keySet) { case (che, pe) =>
      editsByPathEntries.getOrElse(pe, immutable.IndexedSeq(che))
    }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  81. final def updateChildElemsWithNodeSeq(pathEntries: Set[Entry])(f: (ThisElem, Entry) ⇒ IndexedSeq[ThisNode]): ThisElem

    Updates the child elements with the given path entries, applying the passed update function.

    Updates the child elements with the given path entries, applying the passed update function. This is the core method of the update API, and the other methods have implementations that directly or indirectly depend on this method.

    That is, returns:

    if (pathEntries.isEmpty) self
    else {
      val indexesByPathEntries: Seq[(Path.Entry, Int)] =
        collectChildNodeIndexes(pathEntries).toSeq.sortBy(_._2)
    
      // Updating in reverse order of indexes, in order not to invalidate the path entries
      val newChildren = indexesByPathEntries.reverse.foldLeft(self.children) {
        case (accChildNodes, (pathEntry, idx)) =>
          val che = accChildNodes(idx).asInstanceOf[ThisElem]
          accChildNodes.patch(idx, f(che, pathEntry), 1)
      }
      self.withChildren(newChildren)
    }

    If the set of path entries is small, this method is rather efficient.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  82. final def updateElemOrSelf(path: Path, newElem: ThisElem): ThisElem

    Returns updateElemOrSelf(path) { e => newElem }

    Returns updateElemOrSelf(path) { e => newElem }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  83. final def updateElemOrSelf(path: Path)(f: (ThisElem) ⇒ ThisElem): ThisElem

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).

    It can be defined as follows:

    updateElemsOrSelf(Set(path)) { case (e, path) => f(e) }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  84. final def updateElemWithNodeSeq(path: Path, newNodes: IndexedSeq[ThisNode]): ThisElem

    Returns updateElemWithNodeSeq(path) { e => newNodes }

    Returns updateElemWithNodeSeq(path) { e => newNodes }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  85. final def updateElemWithNodeSeq(path: Path)(f: (ThisElem) ⇒ IndexedSeq[ThisNode]): ThisElem

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root). If the given path is the root path, this element itself is returned unchanged.

    This function could be defined as follows:

    updateElemsWithNodeSeq(Set(path)) { case (e, path) => f(e) }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  86. final def updateElems(paths: Set[Path])(f: (ThisElem, Path) ⇒ ThisElem): ThisElem

    Updates the descendant elements with the given paths, applying the passed update function.

    Updates the descendant elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    updateChildElems(pathsByFirstEntry.keySet) {
      case (che, pathEntry) =>
        che.updateElemsOrSelf(pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
          case (elm, path) =>
            f(elm, path.prepend(pathEntry))
        }
    }

    If the set of paths is small, this method is rather efficient.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  87. final def updateElemsOrSelf(paths: Set[Path])(f: (ThisElem, Path) ⇒ ThisElem): ThisElem

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    val descendantUpdateResult =
      updateChildElems(pathsByFirstEntry.keySet) {
        case (che, pathEntry) =>
          // Recursive (but non-tail-recursive) call
          che.updateElemsOrSelf(pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
            case (elm, path) =>
              f(elm, path.prepend(pathEntry))
          }
      }
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else descendantUpdateResult

    In other words, returns:

    val descendantUpdateResult = updateElems(paths)(f)
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else descendantUpdateResult

    If the set of paths is small, this method is rather efficient.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  88. final def updateElemsOrSelfWithNodeSeq(paths: Set[Path])(f: (ThisElem, Path) ⇒ IndexedSeq[ThisNode]): IndexedSeq[ThisNode]

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    val descendantUpdateResult =
      updateChildElemsWithNodeSeq(pathsByFirstEntry.keySet) {
        case (che, pathEntry) =>
          // Recursive (but non-tail-recursive) call
          che.updateElemsOrSelfWithNodeSeq(
            pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
            case (elm, path) =>
              f(elm, path.prepend(pathEntry))
          }
      }
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else Vector(descendantUpdateResult)

    In other words, returns:

    val descendantUpdateResult = updateElemsWithNodeSeq(paths)(f)
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else Vector(descendantUpdateResult)

    If the set of paths is small, this method is rather efficient.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  89. final def updateElemsWithNodeSeq(paths: Set[Path])(f: (ThisElem, Path) ⇒ IndexedSeq[ThisNode]): ThisElem

    Updates the descendant elements with the given paths, applying the passed update function.

    Updates the descendant elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    updateChildElemsWithNodeSeq(pathsByFirstEntry.keySet) {
      case (che, pathEntry) =>
        che.updateElemsOrSelfWithNodeSeq(
          pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
          case (elm, path) =>
            f(elm, path.prepend(pathEntry))
        }
    }

    If the set of paths is small, this method is rather efficient.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  90. final def updateTopmostElems(f: (ThisElem, Path) ⇒ Option[ThisElem]): ThisElem

    Invokes updateElems, passing the topmost non-empty paths for which the passed function is defined.

    Invokes updateElems, passing the topmost non-empty paths for which the passed function is defined. It is equivalent to:

    val mutableEditsByPaths = mutable.Map[Path, ThisElem]()
    
    val foundElems =
      ElemWithPath(self) findTopmostElems { elm =>
        val optResult = f(elm.elem, elm.path)
        if (optResult.isDefined) {
          mutableEditsByPaths += (elm.path -> optResult.get)
        }
        optResult.isDefined
      }
    
    val editsByPaths = mutableEditsByPaths.toMap
    
    updateElems(editsByPaths.keySet) {
      case (elm, path) => editsByPaths.getOrElse(path, elm)
    }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  91. final def updateTopmostElemsOrSelf(f: (ThisElem, Path) ⇒ Option[ThisElem]): ThisElem

    Invokes updateElemsOrSelf, passing the topmost paths for which the passed function is defined.

    Invokes updateElemsOrSelf, passing the topmost paths for which the passed function is defined. It is equivalent to:

    val mutableEditsByPaths = mutable.Map[Path, ThisElem]()
    
    val foundElems =
      ElemWithPath(self) findTopmostElemsOrSelf { elm =>
        val optResult = f(elm.elem, elm.path)
        if (optResult.isDefined) {
          mutableEditsByPaths += (elm.path -> optResult.get)
        }
        optResult.isDefined
      }
    
    val editsByPaths = mutableEditsByPaths.toMap
    
    updateElemsOrSelf(editsByPaths.keySet) {
      case (elm, path) => editsByPaths.getOrElse(path, elm)
    }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  92. final def updateTopmostElemsOrSelfWithNodeSeq(f: (ThisElem, Path) ⇒ Option[IndexedSeq[ThisNode]]): IndexedSeq[ThisNode]

    Invokes updateElemsOrSelfWithNodeSeq, passing the topmost paths for which the passed function is defined.

    Invokes updateElemsOrSelfWithNodeSeq, passing the topmost paths for which the passed function is defined. It is equivalent to:

    val mutableEditsByPaths = mutable.Map[Path, immutable.IndexedSeq[ThisNode]]()
    
    val foundElems =
      ElemWithPath(self) findTopmostElemsOrSelf { elm =>
        val optResult = f(elm.elem, elm.path)
        if (optResult.isDefined) {
          mutableEditsByPaths += (elm.path -> optResult.get)
        }
        optResult.isDefined
      }
    
    val editsByPaths = mutableEditsByPaths.toMap
    
    updateElemsOrSelfWithNodeSeq(editsByPaths.keySet) {
      case (elm, path) => editsByPaths.getOrElse(path, immutable.IndexedSeq(elm))
    }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  93. final def updateTopmostElemsWithNodeSeq(f: (ThisElem, Path) ⇒ Option[IndexedSeq[ThisNode]]): ThisElem

    Invokes updateElemsWithNodeSeq, passing the topmost non-empty paths for which the passed function is defined.

    Invokes updateElemsWithNodeSeq, passing the topmost non-empty paths for which the passed function is defined. It is equivalent to:

    val mutableEditsByPaths = mutable.Map[Path, immutable.IndexedSeq[ThisNode]]()
    
    val foundElems =
      ElemWithPath(self) findTopmostElems { elm =>
        val optResult = f(elm.elem, elm.path)
        if (optResult.isDefined) {
          mutableEditsByPaths += (elm.path -> optResult.get)
        }
        optResult.isDefined
      }
    
    val editsByPaths = mutableEditsByPaths.toMap
    
    updateElemsWithNodeSeq(editsByPaths.keySet) {
      case (elm, path) => editsByPaths.getOrElse(path, immutable.IndexedSeq(elm))
    }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  94. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  95. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  96. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  97. def withAttributes(newAttributes: Map[EName, String]): Elem

    Creates a copy, but with the attributes passed as parameter newAttributes

  98. final def withChildSeqs(newChildSeqs: IndexedSeq[IndexedSeq[ThisNode]]): ThisElem

    Shorthand for withChildren(newChildSeqs.flatten)

    Shorthand for withChildren(newChildSeqs.flatten)

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  99. def withChildren(newChildren: IndexedSeq[Node]): Elem

    Creates a copy, but with (only) the children passed as parameter newChildren

    Creates a copy, but with (only) the children passed as parameter newChildren

    Definition Classes
    ElemUpdatableElemLikeUpdatableElemApi
  100. final def withPatchedChildren(from: Int, newChildren: IndexedSeq[ThisNode], replace: Int): ThisElem

    Shorthand for withChildren(children.patch(from, newChildren, replace))

    Shorthand for withChildren(children.patch(from, newChildren, replace))

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  101. final def withUpdatedChildren(index: Int, newChild: ThisNode): ThisElem

    Shorthand for withChildren(children.updated(index, newChild))

    Shorthand for withChildren(children.updated(index, newChild))

    Definition Classes
    UpdatableElemLikeUpdatableElemApi

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from TransformableElemLike

Inherited from TransformableElemApi

Inherited from UpdatableElemLike

Inherited from UpdatableElemApi

Inherited from ClarkElemLike

Inherited from HasText

Inherited from HasEName

Inherited from IsNavigable

Inherited from ElemLike

Inherited from queryapi.ClarkNodes.Elem

Inherited from HasChildNodesApi

Inherited from AnyElemNodeApi

Inherited from ClarkElemApi

Inherited from HasTextApi

Inherited from HasENameApi

Inherited from IsNavigableApi

Inherited from ElemApi

Inherited from AnyElemApi

Inherited from queryapi.Nodes.Elem

Inherited from CanBeDocumentChild

Inherited from CanBeDocumentChild

Inherited from Node

Inherited from Immutable

Inherited from queryapi.ClarkNodes.Node

Inherited from queryapi.Nodes.Node

Inherited from AnyRef

Inherited from Any

Ungrouped