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 simple

    This package contains the default element implementation.

    This package contains the default element implementation.

    This package depends only on the core and queryapi packages in yaidom, but many other packages do depend on this one.

    Definition Classes
    yaidom
  • CanBeDocBuilderChild
  • CanBeDocumentChild
  • Comment
  • CommentBuilder
  • ConverterToDocument
  • ConverterToElem
  • DocBuilder
  • Document
  • DocumentConverter
  • Elem
  • ElemBuilder
  • ElemConverter
  • EntityRef
  • EntityRefBuilder
  • Node
  • NodeBuilder
  • ProcessingInstruction
  • ProcessingInstructionBuilder
  • Text
  • TextBuilder

final class Elem extends CanBeDocumentChild with queryapi.ScopedNodes.Elem with ScopedElemLike with UpdatableElemLike with TransformableElemLike

Immutable, thread-safe element node. It is the default element implementation in yaidom. As the default element implementation among several alternative element implementations, it strikes a balance between loss-less roundtripping and composability.

The parsers and serializers in packages eu.cdevreeze.yaidom.parse and eu.cdevreeze.yaidom.print return and take these default elements (or the corresponding Document instances), respectively.

As for its query API, class eu.cdevreeze.yaidom.simple.Elem is among the most powerful element implementations offered by yaidom. These elements offer all of the eu.cdevreeze.yaidom.queryapi.ElemApi, eu.cdevreeze.yaidom.queryapi.UpdatableElemApi and eu.cdevreeze.yaidom.queryapi.TransformableElemApi query APIs, and more.

See the documentation of the mixed-in query API traits for more details on the uniform query API offered by this class.

The following example illustrates the use of the yaidom uniform query API in combination with some Elem-specific methods. In this XML scripting example the namespace prefix "xsd" is replaced by prefix "xs", including those in QName-valued attributes. The trivial XML file of this example is the following XML Schema:

<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>

The edit action can be performed on this schemaElem as follows, starting with some checks:

// All descendant-or-self elements have the same Scope, mapping only prefix "xsd".
require(schemaElem.findAllElemsOrSelf.map(_.scope).distinct == List(Scope.from("xsd" -> "http://www.w3.org/2001/XMLSchema")))

// All descendant-or-self elements have a QName with prefix "xsd".
require(schemaElem.findAllElemsOrSelf.map(_.qname.prefixOption).distinct == List(Some("xsd")))

// All descendant-or-self elements have unprefixed attributes only.
require(schemaElem.findAllElemsOrSelf.flatMap(_.attributes.toMap.keySet.map(_.prefixOption)).distinct == List(None))

// All descendant-or-self elements with "type" attributes contain only QNames with prefix "xsd" in the values of those attributes.
require(schemaElem.filterElemsOrSelf(e => (e \@ EName("type")).isDefined).forall(e => e.attributeAsQName(EName("type")).prefixOption.contains("xsd")))

// Replaces prefix "xsd" by "xs" throughout the element tree, including in "type" attributes.
val editedSchemaElem = schemaElem transformElemsOrSelf { elem =>
  val newScope = (elem.scope -- Set("xsd")) ++ Scope.from("xs" -> "http://www.w3.org/2001/XMLSchema")
  val newQName = QName("xs", elem.qname.localPart)
  val newTypeAttrOption = elem.attributeAsQNameOption(EName("type")).map(attr => QName("xs", attr.localPart).toString)

  elem.copy(qname = newQName, scope = newScope).plusAttributeOption(QName("type"), newTypeAttrOption)
}

Note that besides the uniform query API, this example uses some Elem-specific methods, such as attributeAsQName, copy and plusAttributeOption.

Class Elem is immutable, and (should be) thread-safe. Hence, Elems do not know about their parent element, if any.

An Elem has the following state:

Note that namespace declarations are not considered to be attributes in Elem, just like in the rest of yaidom. Elem construction is unsuccessful if the element name and/or some attribute names cannot be resolved using the Scope of the element (ignoring the default namespace, if any, for attributes). As can be seen from the above-mentioned state, namespaces are first-class citizens.

Elems can (relatively easily) be constructed manually in a bottom-up manner. Yet care must be taken to give the element and its descendants the correct Scope. Otherwise it is easy to introduce (prefixed) namespace undeclarations, which are not allowed in XML 1.0. The underlying issue is that functional Elem trees are created in a bottom-up manner, whereas namespace scoping works in a top-down manner. This is not a big issue in practice, since manual Elem creation is rather rare, and it is always possible to call method notUndeclaringPrefixes afterwards. An alternative method to create element trees by hand uses class eu.cdevreeze.yaidom.simple.ElemBuilder. A manually created ElemBuilder can be converted to an Elem by calling method build.

Round-tripping (parsing and serializing) is not entirely loss-less, but (in spite of the good composability and rather small state) not much is lost. Comments, processing instructions and entity references are retained. Attribute order is retained, although according to the XML Infoset this order is irrelevant. Namespace declaration order is not necessarily retained, however. Superfluous namespace declarations are also lost. (That is because namespace declarations are not explicitly stored in Elems, but are implicit, viz. parentElem.scope.relativize(this.scope)). The short versus long form of an empty element is also not remembered.

Equality has not been defined for class Elem (that is, it is reference equality). There is no clear sensible notion of equality for XML trees at the abstraction level of Elem. For example, think about prefixes, "ignorable whitespace", DTDs and XSDs, etc.

Annotations
@SerialVersionUID()
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Elem
  2. TransformableElemLike
  3. TransformableElemApi
  4. UpdatableElemLike
  5. UpdatableElemApi
  6. ScopedElemLike
  7. ClarkElemLike
  8. HasText
  9. HasEName
  10. IsNavigable
  11. ElemLike
  12. Elem
  13. ScopedElemApi
  14. HasScopeApi
  15. HasQNameApi
  16. Elem
  17. HasChildNodesApi
  18. AnyElemNodeApi
  19. ClarkElemApi
  20. HasTextApi
  21. HasENameApi
  22. IsNavigableApi
  23. ElemApi
  24. AnyElemApi
  25. Elem
  26. CanBeDocumentChild
  27. CanBeDocumentChild
  28. CanBeDocumentChild
  29. CanBeDocumentChild
  30. Node
  31. Serializable
  32. Serializable
  33. Immutable
  34. Node
  35. Node
  36. Node
  37. AnyRef
  38. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Elem(qname: QName, attributes: IndexedSeq[(QName, String)], scope: Scope, 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
    ElemTransformableElemLikeTransformableElemApiUpdatableElemLikeUpdatableElemApiScopedElemLikeClarkElemLikeIsNavigableElemLikeElemScopedElemApiElemHasChildNodesApiClarkElemApiIsNavigableApiElemApiAnyElemApi
  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
    ElemElemElemAnyElemNodeApi

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 attributeAsQName(expandedName: EName): QName

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

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

    Definition Classes
    ScopedElemLikeScopedElemApi
  11. final def attributeAsQNameOption(expandedName: EName): Option[QName]

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

    Returns the QName value of the attribute with the given expanded name, if any, wrapped in an Option. If the attribute exists, but its value is not a QName, an exception is thrown.

    Definition Classes
    ScopedElemLikeScopedElemApi
  12. final def attributeAsResolvedQName(expandedName: EName): EName

    Returns the resolved QName value (as EName) of the attribute with the given expanded name, and throws an exception otherwise

    Returns the resolved QName value (as EName) of the attribute with the given expanded name, and throws an exception otherwise

    Definition Classes
    ScopedElemLikeScopedElemApi
  13. final def attributeAsResolvedQNameOption(expandedName: EName): Option[EName]

    Returns the resolved QName value (as EName) of the attribute with the given expanded name, if any, wrapped in an Option.

    Returns the resolved QName value (as EName) of the attribute with the given expanded name, if any, wrapped in an Option. None is returned if the attribute does not exist. If the QName value cannot be resolved given the scope of the element, an exception is thrown.

    Definition Classes
    ScopedElemLikeScopedElemApi
  14. 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
  15. def attributeScope: Scope

    The attribute Scope, which is the same Scope but without the default namespace (which is not used for attributes)

  16. val attributes: IndexedSeq[(QName, String)]

    The attributes of the element as mapping from QNames to values

    The attributes of the element as mapping from QNames to values

    Definition Classes
    ElemHasQNameApi
  17. 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
  18. 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
  19. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  20. def coalesceAllAdjacentText: Elem

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

  21. 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.

  22. 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.

  23. 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
  24. def commentChildren: IndexedSeq[Comment]

    Returns the comment children

  25. def copy(qname: QName = this.qname, attributes: IndexedSeq[(QName, String)] = this.attributes, scope: Scope = this.scope, children: IndexedSeq[Node] = this.children): Elem

    Creates a copy, altered with the explicitly passed parameters (for qname, attributes, scope and children).

  26. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  27. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  28. 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
  29. 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
  30. 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
  31. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  32. def findAllChildElems: IndexedSeq[Elem]

    Returns the element children

    Returns the element children

    Definition Classes
    ElemElemLikeElemApi
  33. 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
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. 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
  42. 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
  43. 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
  44. 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
  45. 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
  46. final def getChildElemByPathEntry(entry: Entry): ThisElem

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

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

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

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

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

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

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

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

    Definition Classes
    IsNavigableIsNavigableApi
  50. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  51. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  52. 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
  53. def minusAttribute(attributeName: QName): Elem

    Functionally removes the given attribute, if present.

    Functionally removes the given attribute, if present.

    More precisely, returns withAttributes(thisElem.attributes filterNot (_._1 == attributeName)).

  54. 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
  55. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  56. 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.

  57. final def normalizedText: String

    Returns XmlStringUtils.normalizeString(text).

    Returns XmlStringUtils.normalizeString(text).

    Definition Classes
    HasTextHasTextApi
  58. def notUndeclaringPrefixes(parentScope: Scope): Elem

    Returns an "equivalent" Elem in which the implicit namespace declarations throughout the tree do not contain any prefixed namespace undeclarations, given the passed parent Scope.

    Returns an "equivalent" Elem in which the implicit namespace declarations throughout the tree do not contain any prefixed namespace undeclarations, given the passed parent Scope.

    This method could be defined by recursion as follows:

    def notUndeclaringPrefixes(parentScope: Scope): Elem = {
      val newScope = parentScope.withoutDefaultNamespace ++ this.scope
      this.copy(scope = newScope) transformChildElems { e => e.notUndeclaringPrefixes(newScope) }
    }

    It can be proven by structural induction that for each parentScope the XML remains the "same":

    resolved.Elem.from(this.notUndeclaringPrefixes(parentScope)) == resolved.Elem.from(this)

    Moreover, there are no prefixed namespace undeclarations:

    NodeBuilder.fromElem(this.notUndeclaringPrefixes(parentScope))(Scope.Empty).findAllElemsOrSelf.
      map(_.namespaces.withoutDefaultNamespace.retainingUndeclarations).toSet ==
        Set(Declarations.Empty)

    Note that XML 1.0 does not allow prefix undeclarations, and this method helps avoid them, while preserving the "same" XML. So, when manipulating an Elem tree, calling notUndeclaringPrefixes(Scope.Empty) on the document element results in an equivalent Elem that has no prefixed namespace undeclarations anywhere in the tree.

  59. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  60. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  61. def plusAttribute(attributeName: QName, attributeValue: String): Elem

    Functionally adds or updates the given attribute.

    Functionally adds or updates the given attribute.

    More precisely, if an attribute with the same name exists at position idx (0-based), withAttributes(attributes.updated(idx, (attributeName -> attributeValue))) is returned. Otherwise, withAttributes(attributes :+ (attributeName -> attributeValue)) is returned.

  62. def plusAttributeOption(attributeName: QName, 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) self else plusAttribute(attributeName, attributeValueOption.get).

  63. 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
  64. 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
  65. 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
  66. 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
  67. 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
  68. def prettify(indent: Int, useTab: Boolean = false, newLine: String = "\n"): Elem

    "Prettifies" this Elem.

    "Prettifies" this Elem. That is, first calls method removeAllInterElementWhitespace, and then transforms the result by inserting text nodes with newlines and whitespace for indentation.

  69. def processingInstructionChildren: IndexedSeq[ProcessingInstruction]

    Returns the processing instruction children

  70. val qname: QName

    The QName of the element

    The QName of the element

    Definition Classes
    ElemHasQNameApi
  71. 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.

  72. val resolvedAttributes: IndexedSeq[(EName, String)]

    The attributes as an ordered mapping from ENames (instead of QNames) to values, obtained by resolving attribute QNames against the attribute scope

    The attributes as an ordered mapping from ENames (instead of QNames) to values, obtained by resolving attribute QNames against the attribute scope

    Definition Classes
    ElemHasENameApi
  73. val resolvedName: EName

    The Elem name as EName, obtained by resolving the element QName against the Scope

    The Elem name as EName, obtained by resolving the element QName against the Scope

    Definition Classes
    ElemHasENameApi
  74. val scope: Scope

    The Scope stored with the element

    The Scope stored with the element

    Definition Classes
    ElemHasScopeApi
  75. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  76. def text: String

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

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

    Definition Classes
    ElemHasTextApi
  77. final def textAsQName: QName

    Returns QName(text.trim)

    Returns QName(text.trim)

    Definition Classes
    ScopedElemLikeScopedElemApi
  78. final def textAsResolvedQName: EName

    Returns the equivalent of scope.resolveQNameOption(textAsQName).get

    Returns the equivalent of scope.resolveQNameOption(textAsQName).get

    Definition Classes
    ScopedElemLikeScopedElemApi
  79. def textChildren: IndexedSeq[Text]

    Returns the text children

  80. def thisElem: ThisElem

    This element itself.

    This element itself.

    Definition Classes
    ElemAnyElemApi
  81. final def toString(): String

    Returns the tree representation string corresponding to this element, that is, toTreeRepr.

    Returns the tree representation string corresponding to this element, that is, toTreeRepr.

    Possibly expensive, especially for large XML trees! Note that the toString method is often called implicitly, for example in logging statements. So, if the toString method is not used carefully, OutOfMemoryErrors may occur.

    Definition Classes
    Node → AnyRef → Any
  82. final def toTreeRepr: String

    Same as toTreeRepr(emptyScope)

    Same as toTreeRepr(emptyScope)

    Definition Classes
    Node
  83. final def toTreeRepr(parentScope: Scope): String

    Returns the tree representation String, conforming to the tree representation DSL that creates NodeBuilders.

    Returns the tree representation String, conforming to the tree representation DSL that creates NodeBuilders. That is, it does not correspond to the tree representation DSL of Nodes, but of NodeBuilders!

    There are a couple of advantages of this method compared to some "toXmlString" method which returns the XML string:

    • The parsed XML tree is made explicit, which makes debugging far easier, especially since method toString invokes this method
    • The output of method toTreeRepr clearly corresponds to a NodeBuilder, and can indeed be parsed into one
    • That toTreeRepr output is even valid Scala code
    • When parsing the string into a NodeBuilder, the following is out of scope: character escaping (for XML), entity resolving, "ignorable" whitespace handling, etc.
    Definition Classes
    Node
  84. def transformAllText(f: (Text) ⇒ Text): Elem

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

  85. 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
  86. 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
  87. 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
  88. 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
  89. 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
  90. 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
  91. final def trimmedText: String

    Returns text.trim.

    Returns text.trim.

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

    Returns updateChildElem(pathEntry) { e => newElem }

    Returns updateChildElem(pathEntry) { e => newElem }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  93. 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
  94. final def updateChildElemWithNodeSeq(pathEntry: Entry, newNodes: IndexedSeq[ThisNode]): ThisElem

    Returns updateChildElemWithNodeSeq(pathEntry) { e => newNodes }

    Returns updateChildElemWithNodeSeq(pathEntry) { e => newNodes }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  95. 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
  96. 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
  97. 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
  98. 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
  99. 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
  100. final def updateElemOrSelf(path: Path, newElem: ThisElem): ThisElem

    Returns updateElemOrSelf(path) { e => newElem }

    Returns updateElemOrSelf(path) { e => newElem }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  101. 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
  102. final def updateElemWithNodeSeq(path: Path, newNodes: IndexedSeq[ThisNode]): ThisElem

    Returns updateElemWithNodeSeq(path) { e => newNodes }

    Returns updateElemWithNodeSeq(path) { e => newNodes }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  103. 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
  104. 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
  105. 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
  106. 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
  107. 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
  108. 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
  109. 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
  110. 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
  111. 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
  112. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  113. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  114. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  115. def withAttributes(newAttributes: IndexedSeq[(QName, String)]): Elem

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

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

    Shorthand for withChildren(newChildSeqs.flatten)

    Shorthand for withChildren(newChildSeqs.flatten)

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  117. 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
  118. 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
  119. 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 TransformableElemLike

Inherited from TransformableElemApi

Inherited from UpdatableElemLike

Inherited from UpdatableElemApi

Inherited from ScopedElemLike

Inherited from ClarkElemLike

Inherited from HasText

Inherited from HasEName

Inherited from IsNavigable

Inherited from ElemLike

Inherited from queryapi.ScopedNodes.Elem

Inherited from ScopedElemApi

Inherited from HasScopeApi

Inherited from HasQNameApi

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 Node

Inherited from Serializable

Inherited from Serializable

Inherited from Immutable

Inherited from queryapi.ScopedNodes.Node

Inherited from queryapi.ClarkNodes.Node

Inherited from queryapi.Nodes.Node

Inherited from AnyRef

Inherited from Any

Ungrouped