Shorthand for filterChildElems(expandedName)
.
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 attributeOption(expandedName)
Shorthand for filterElemsOrSelf(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(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, and throws an exception otherwise.
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
.
Returns the paths of child elements obeying the given predicate
Returns the child elements with the given expanded name
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 paths of descendant-or-self elements that obey the given predicate.
Returns the paths of descendant-or-self elements that obey the given predicate.
That is, the result is equivalent to the paths of findAllElemsOrSelf filter p
.
Returns the paths of descendant elements obeying the given predicate, that is, the paths of findAllElems filter p
Returns the descendant elements with the given expanded name
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 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
.
Returns the Path
entries of all child elements, in the correct order.
Returns the Path
entries of all child elements, in the correct order.
Equivalent to findAllChildElemsWithPathEntries map { _._2 }
.
Returns findAllChildElemsWithPathEntries map { case (e, pe) => Path.from(pe) }
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 child elements with their Path
entries, in the correct order.
Returns all child elements with their Path
entries, in the correct order. This method should be very efficient.
The implementation must be such that the following holds: (findAllChildElemsWithPathEntries map (_._1)) == findAllChildElems
Returns the path of this element followed by the paths of all descendant elements (that is, the descendant-or-self elements)
Returns the paths of all descendant elements (not including this element).
Returns the paths of all descendant elements (not including this element). Equivalent to findAllElemOrSelfPaths.drop(1)
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 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
.
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
.
Returns the path of the first found child element obeying the given predicate, if any, wrapped in an Option
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 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 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
.
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
.
Note that for each non-empty Path, we have:
findElemOrSelfByPath(path) == findChildElemByPathEntry(path.firstEntry) flatMap (e => e.findElemOrSelfByPath(path.withoutFirstEntry))
Returns the path of the first found (topmost) descendant-or-self element obeying the given predicate, if any, wrapped in an Option
Returns the path of the first found (topmost) descendant element obeying the given predicate, if any, wrapped in an Option
Returns the paths of the descendant-or-self elements that obey the given predicate, such that no ancestor obeys the predicate.
Returns the paths of the descendant elements obeying the given predicate that have no ancestor obeying the predicate
Returns the descendant elements with the given expanded name that have no ancestor with the same name
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 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 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
.
Returns (the equivalent of) findChildElemByPathEntry(entry).get
Returns (the equivalent of) findChildElemByPathEntry(entry).get
Returns the path of the single child element obeying the given predicate, and throws an exception otherwise
Returns (the equivalent of) findElemOrSelfByPath(path).get
Returns (the equivalent of) findElemOrSelfByPath(path).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
Resolved name of the element, as EName
This is the Path-aware part of the yaidom uniform query API. It is a sub-trait of trait eu.cdevreeze.yaidom.NavigableElemApi. Only a few 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 eu.cdevreeze.yaidom.PathAwareElemLike. That trait only knows about elements (and not about other nodes), and only knows the following about elements:
)ParentElemLike
)ElemLike
)ElemLike
Using this minimal knowledge alone, that trait not only offers the methods of its parent trait, but also:
query methods, but returningParentElemLike
objects instead of elementsPath
In other words, the
trait is quite a rich query API, considering the minimal knowledge it needs to have about elements.PathAwareElemApi
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.PathAwareElemLike
PathAwareElemApi examples
To illustrate the use of this API, consider the following example XML:
Suppose this XML has been parsed into eu.cdevreeze.yaidom.Elem instance
. Then we can perform the following query, using only thebookstoreElem
query API:ElemApi
This is a top-down approach for finding Scala books. A bottom-up approach, using the
query API, could be coded as follows:PathAwareElemApi
A few remarks are in order:
(orgetElemOrSelfByPath
) on the correct elementfindElemOrSelfByPath
take predicates on elements, and not on paths or element-path-combinations. Not much would have been gained from that, because typical queries for paths containPathAwareElemApi
calls anyway. After all, what else are paths for?getElemOrSelfByPath
In spite of these remarks, the methods specific to the
trait are a nice tool in the yaidom querying toolbox.PathAwareElemApi
PathAwareElemApi more formally
In order to get started using the API, this more formal section can safely be skipped. On the other hand, this section may provide a deeper understanding of the API.
The
trait can be understood more formally, as shown below.PathAwareElemApi
The most fundamental methods of this trait are
andfindAllChildElemsWithPathEntries
. The semantics of the other methods can be defined directly or indirectly in terms of methodfindChildElemByPathEntry
.findAllChildElemsWithPathEntries
The following must hold (for
, which has structural equality defined):resolved.Elem
The basic operations definable in terms of method
arefindAllChildElemsWithPathEntries
,filterChildElemPaths
andfilterElemOrSelfPaths
, analogous to traitfindTopmostElemOrSelfPaths
. Their semantics must be as if they had been defined as follows:ParentElemApi
Moreover, we could have defined:
and:
Then, analogously to
, the following properties hold:ParentElemApi
etc.
Knowing that for
instanceresolved.Elem
, we have:elem
it follows that:
etc., where
is defined recursively, using methodfindElemOrSelfByPath
.findChildElemByPathEntry
No proofs are provided. Note that the similarities with trait
are striking.ParentElemLike
The captured element subtype