Shorthand for filterChildElems(expandedName)
.
Shorthand for filterChildElems(p)
.
Shorthand for filterChildElems(p)
. Use this shorthand only if the predicate is a short expression.
Shorthand for attributeOption(expandedName)
Shorthand for filterElemsOrSelf(expandedName)
.
Shorthand for filterElemsOrSelf(p)
.
Shorthand for filterElemsOrSelf(p)
. Use this shorthand only if the predicate is a short expression.
Shorthand for findTopmostElemsOrSelf(expandedName)
.
Shorthand for findTopmostElemsOrSelf(p)
.
Shorthand for findTopmostElemsOrSelf(p)
. Use this shorthand only if the predicate is a short expression.
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, if any, wrapped in an Option
.
Returns the child elements with the given expanded name
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: E => Boolean): immutable.IndexedSeq[E] = this.findAllChildElems.filter(p)
Returns the descendant elements with the given expanded name
Returns the descendant elements obeying the given predicate.
Returns the descendant elements obeying the given predicate. This method could be defined as:
this.findAllChildElems flatMap (_.filterElemsOrSelf(p))
Returns the descendant-or-self elements that have the given expanded name
Returns the descendant-or-self elements obeying the given predicate.
Returns the descendant-or-self elements obeying the given predicate. This method could be defined as:
def filterElemsOrSelf(p: E => Boolean): immutable.IndexedSeq[E] = Vector(this).filter(p) ++ (this.findAllChildElems flatMap (_.filterElemsOrSelf(p)))
It can be proven that the result is equivalent to findAllElemsOrSelf filter p
.
Core method that returns all child elements, in the correct order.
Core method that returns all child elements, in the correct order. Other operations can be defined in terms of this one.
Returns all descendant elements (not including this element).
Returns all descendant elements (not including this element). This method could be defined as filterElems { e => true }
.
Equivalent to findAllElemsOrSelf.drop(1)
.
Returns this element followed by all descendant elements (that is, the descendant-or-self elements).
Returns this element followed by all descendant elements (that is, the descendant-or-self elements).
This method could be defined as filterElemsOrSelf { e => true }
.
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.
Returns the first found child element with the given expanded name, if any, wrapped in an Option
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
.
Returns the first found (topmost) descendant element with the given expanded name, if any, wrapped in an Option
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
.
Returns the first found (topmost) descendant-or-self element with the given expanded name, 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
.
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
.
Returns the descendant elements with the given expanded name that have no ancestor with the same name
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))
Returns the descendant-or-self elements with the given expanded name that have no ancestor with the same name
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: E => Boolean): immutable.IndexedSeq[E] = if (p(this)) Vector(this) else (this.findAllChildElems flatMap (_.findTopmostElemsOrSelf(p)))
Returns the single child element with the given expanded name, and throws an exception otherwise
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
.
The local name (or local part).
The local name (or local part). Convenience method.
The attributes as a mapping from EName
s (instead of QName
s) to values.
The attributes as a mapping from EName
s (instead of QName
s) to values.
The implementation must ensure that resolvedAttributes.toMap.size == resolvedAttributes.size
.
Namespace declarations are not considered attributes in yaidom, so are not included in the result.
Resolved name of the element, as EName
This is the best known part of the yaidom uniform query API. It is a sub-trait of trait ParentElemApi. Many DOM-like element implementations in yaidom mix in this trait (indirectly, because some implementing sub-trait is mixed in), thus sharing this query API.
This trait typically does not show up in application code using yaidom, yet its (uniform) API does. Hence, it makes sense to read the documentation of this trait, knowing that the API is offered by multiple element implementations.
This trait is purely abstract. The most common implementation of this trait is ElemLike. That trait only knows about elements (and not about other nodes), and only knows the following about elements:
s) to attribute valuesEName
Using this minimal knowledge alone, that trait offers methods to query for descendant elements, descendant-or-self methods, or sub-collections thereof. Element sub-collections can be queried by passing a predicate (as offered by the super-trait), or simply by passing an element
.EName
It is this minimal knowledge that makes this API uniform. On the one hand, that minimal knowledge is enough knowledge for providing a rather rich
query API, and on the other hand, that minimal knowledge is so fundamental to DOM-like elements that most yaidom DOM-like element implementations indeed offer this API.ElemApi
This query API leverages the Scala Collections API. Query results can be manipulated using the Collections API, and the query API implementation (in
) uses the Collections API internally.ElemLike
ElemApi examples
It is easy to show that this small query API is already very useful. Consider the following example XML:
Suppose this XML has been parsed into Elem instance
. Then we can perform the following queries:bookstoreElem
Using more
query methods, we could instead have written:ParentElemApi
By replacing operator notation, we get the following equivalent queries:
The queries above only use the following knowledge about the DOM-like elements: they offer the
andElemApi
APIs. As a consequence, the exact same queries work for other DOM-like element implementations as well. That is,HasText
could instead have been of type Elem, Elem, DomElem or ScalaXmlElem. Hence thebookstoreElem
trait indeed offers a uniform element query API.ElemApi
ElemApi more formally
From a formal point of view,
offers little of interest. After all, given super-traitElemApi
, as well as methodsParentElemApi
andresolvedName
, the other methods are trivial to implement.resolvedAttributes
For example, the semantics of method
(taking anfilterChildElems
) is trivially defined as follows:EName
elem.filterChildElems(ename) == elem.filterChildElems(e => e.resolvedName == ename)
Other
methods taking a predicate also have a counterpart inParentElemApi
taking just anElemApi
, and the latter ones are trivially defined in terms of the former ones, just likeEName
(taking anfilterChildElems
) above. After all, parent traitEName
is the foundation of the yaidom query API, yet sub-traitParentElemApi
makes it much more useful in practice, by adding some knowledge about element names and attributes.ElemApi
The captured element subtype