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:
- the eu.cdevreeze.yaidom.core.QName of the element
- the attributes of the element, mapping attribute eu.cdevreeze.yaidom.core.QNames to String values
- a eu.cdevreeze.yaidom.core.Scope mapping prefixes to namespace URIs
- an immutable collection of child nodes
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()
- Alphabetic
- By Inheritance
- Elem
- TransformableElemLike
- TransformableElemApi
- UpdatableElemLike
- UpdatableElemApi
- ScopedElemLike
- ClarkElemLike
- HasText
- HasEName
- IsNavigable
- ElemLike
- Elem
- ScopedElemApi
- HasScopeApi
- HasQNameApi
- Elem
- HasChildNodesApi
- AnyElemNodeApi
- ClarkElemApi
- HasTextApi
- HasENameApi
- IsNavigableApi
- ElemApi
- AnyElemApi
- Elem
- CanBeDocumentChild
- CanBeDocumentChild
- CanBeDocumentChild
- CanBeDocumentChild
- Node
- Serializable
- Serializable
- Immutable
- Node
- Node
- Node
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
Type Members
-
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
- Elem → TransformableElemLike → TransformableElemApi → UpdatableElemLike → UpdatableElemApi → ScopedElemLike → ClarkElemLike → IsNavigable → ElemLike → Elem → ScopedElemApi → Elem → HasChildNodesApi → ClarkElemApi → IsNavigableApi → ElemApi → AnyElemApi
-
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
- Elem → Elem → Elem → AnyElemNodeApi
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
\(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]
Shorthand for
filterChildElems(p)
. -
final
def
\@(expandedName: EName): Option[String]
Shorthand for
attributeOption(expandedName)
.Shorthand for
attributeOption(expandedName)
.- Definition Classes
- HasEName → HasENameApi
-
final
def
\\(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]
Shorthand for
filterElemsOrSelf(p)
. -
final
def
\\!(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]
Shorthand for
findTopmostElemsOrSelf(p)
. -
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
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
- HasEName → HasENameApi
-
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
- ScopedElemLike → ScopedElemApi
-
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
- ScopedElemLike → ScopedElemApi
-
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
- ScopedElemLike → ScopedElemApi
-
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
- ScopedElemLike → ScopedElemApi
-
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
- HasEName → HasENameApi
-
def
attributeScope: Scope
The attribute
Scope
, which is the sameScope
but without the default namespace (which is not used for attributes) -
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
- Elem → HasQNameApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- Elem → UpdatableElemLike → UpdatableElemApi → HasChildNodesApi
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
coalesceAllAdjacentText: Elem
Returns a copy where adjacent text nodes have been combined into one text node, throughout the node tree
-
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.
-
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 bynormalizeAllText
, but more efficient. -
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
- Elem → UpdatableElemLike → UpdatableElemApi
-
def
commentChildren: IndexedSeq[Comment]
Returns the comment children
-
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).
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
filterChildElems(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]
Returns the child elements obeying the given predicate.
-
final
def
filterElems(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]
Returns the descendant elements obeying the given predicate, in document order.
-
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
. -
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
findAllChildElems: IndexedSeq[Elem]
Returns the element children
-
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
- ClarkElemLike → IsNavigable → IsNavigableApi
-
final
def
findAllElems: IndexedSeq[ThisElem]
Returns all descendant elements (not including this element), in document order.
-
final
def
findAllElemsOrSelf: IndexedSeq[ThisElem]
Returns this element followed by all descendant elements (that is, the descendant-or-self elements), in document order.
-
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
- HasEName → HasENameApi
-
final
def
findChildElem(p: (ThisElem) ⇒ Boolean): Option[ThisElem]
Returns the first found child element obeying the given predicate, if any, wrapped in an
Option
. -
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 anOption
.Finds the child element with the given
Path.Entry
(where this element is the root), if any, wrapped in anOption
.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
- ClarkElemLike → IsNavigable → IsNavigableApi
-
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
. -
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
. -
final
def
findElemOrSelfByPath(path: Path): Option[ThisElem]
Finds the element with the given
Path
(where this element is the root), if any, wrapped in anOption
.Finds the element with the given
Path
(where this element is the root), if any, wrapped in anOption
.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
- IsNavigable → IsNavigableApi
-
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
- IsNavigable → IsNavigableApi
-
final
def
findTopmostElems(p: (ThisElem) ⇒ Boolean): IndexedSeq[ThisElem]
Returns the descendant elements obeying the given predicate that have no ancestor obeying the predicate.
-
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)))
-
final
def
getChildElem(p: (ThisElem) ⇒ Boolean): ThisElem
Returns the single child element obeying the given predicate, and throws an exception otherwise.
-
final
def
getChildElemByPathEntry(entry: Entry): ThisElem
Returns (the equivalent of)
findChildElemByPathEntry(entry).get
Returns (the equivalent of)
findChildElemByPathEntry(entry).get
- Definition Classes
- IsNavigable → IsNavigableApi
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
getElemOrSelfByPath(path: Path): ThisElem
Returns (the equivalent of)
findElemOrSelfByPath(path).get
Returns (the equivalent of)
findElemOrSelfByPath(path).get
- Definition Classes
- IsNavigable → IsNavigableApi
-
final
def
getReverseAncestryOrSelfByPath(path: Path): IndexedSeq[ThisElem]
Returns (the equivalent of)
findReverseAncestryOrSelfByPath(path).get
Returns (the equivalent of)
findReverseAncestryOrSelfByPath(path).get
- Definition Classes
- IsNavigable → IsNavigableApi
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
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
- HasEName → HasENameApi
-
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))
. -
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
- UpdatableElemLike → UpdatableElemApi
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
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
. -
final
def
normalizedText: String
Returns
XmlStringUtils.normalizeString(text)
.Returns
XmlStringUtils.normalizeString(text)
.- Definition Classes
- HasText → HasTextApi
-
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. -
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
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. -
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)
. -
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
- UpdatableElemLike → UpdatableElemApi
-
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. Ifindex > children.size
, throws an exception.Afterwards, the resulting element indeed has the given child at position
index
(0-based).- Definition Classes
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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. -
def
processingInstructionChildren: IndexedSeq[ProcessingInstruction]
Returns the processing instruction children
-
val
qname: QName
The QName of the element
The QName of the element
- Definition Classes
- Elem → HasQNameApi
-
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.
-
val
resolvedAttributes: IndexedSeq[(EName, String)]
The attributes as an ordered mapping from
EName
s (instead ofQName
s) to values, obtained by resolving attributeQName
s against the attribute scopeThe attributes as an ordered mapping from
EName
s (instead ofQName
s) to values, obtained by resolving attributeQName
s against the attribute scope- Definition Classes
- Elem → HasENameApi
-
val
resolvedName: EName
The
Elem
name asEName
, obtained by resolving the elementQName
against theScope
The
Elem
name asEName
, obtained by resolving the elementQName
against theScope
- Definition Classes
- Elem → HasENameApi
-
val
scope: Scope
The Scope stored with the element
The Scope stored with the element
- Definition Classes
- Elem → HasScopeApi
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
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
- Elem → HasTextApi
-
final
def
textAsQName: QName
Returns
QName(text.trim)
Returns
QName(text.trim)
- Definition Classes
- ScopedElemLike → ScopedElemApi
-
final
def
textAsResolvedQName: EName
Returns the equivalent of
scope.resolveQNameOption(textAsQName).get
Returns the equivalent of
scope.resolveQNameOption(textAsQName).get
- Definition Classes
- ScopedElemLike → ScopedElemApi
-
def
textChildren: IndexedSeq[Text]
Returns the text children
-
def
thisElem: ThisElem
This element itself.
This element itself.
- Definition Classes
- Elem → AnyElemApi
-
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 thetoString
method is not used carefully, OutOfMemoryErrors may occur.- Definition Classes
- Node → AnyRef → Any
-
final
def
toTreeRepr: String
Same as
toTreeRepr(emptyScope)
Same as
toTreeRepr(emptyScope)
- Definition Classes
- Node
-
final
def
toTreeRepr(parentScope: Scope): String
Returns the tree representation String, conforming to the tree representation DSL that creates
NodeBuilder
s.Returns the tree representation String, conforming to the tree representation DSL that creates
NodeBuilder
s. That is, it does not correspond to the tree representation DSL ofNode
s, but ofNodeBuilder
s!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 aNodeBuilder
, 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
-
def
transformAllText(f: (Text) ⇒ Text): Elem
Returns a copy where text nodes have been transformed, throughout the node tree.
-
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
- Elem → TransformableElemLike → TransformableElemApi
-
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
- Elem → TransformableElemLike → TransformableElemApi
-
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
- TransformableElemLike → TransformableElemApi
-
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
- TransformableElemLike → TransformableElemApi
-
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
- TransformableElemLike → TransformableElemApi
-
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
- TransformableElemLike → TransformableElemApi
-
final
def
trimmedText: String
Returns
text.trim
.Returns
text.trim
.- Definition Classes
- HasText → HasTextApi
-
final
def
updateChildElem(pathEntry: Entry, newElem: ThisElem): ThisElem
Returns
updateChildElem(pathEntry) { e => newElem }
Returns
updateChildElem(pathEntry) { e => newElem }
- Definition Classes
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
final
def
updateChildElemWithNodeSeq(pathEntry: Entry, newNodes: IndexedSeq[ThisNode]): ThisElem
Returns
updateChildElemWithNodeSeq(pathEntry) { e => newNodes }
Returns
updateChildElemWithNodeSeq(pathEntry) { e => newNodes }
- Definition Classes
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
final
def
updateElemOrSelf(path: Path, newElem: ThisElem): ThisElem
Returns
updateElemOrSelf(path) { e => newElem }
Returns
updateElemOrSelf(path) { e => newElem }
- Definition Classes
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
final
def
updateElemWithNodeSeq(path: Path, newNodes: IndexedSeq[ThisNode]): ThisElem
Returns
updateElemWithNodeSeq(path) { e => newNodes }
Returns
updateElemWithNodeSeq(path) { e => newNodes }
- Definition Classes
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
withAttributes(newAttributes: IndexedSeq[(QName, String)]): Elem
Creates a copy, but with the attributes passed as parameter
newAttributes
-
final
def
withChildSeqs(newChildSeqs: IndexedSeq[IndexedSeq[ThisNode]]): ThisElem
Shorthand for
withChildren(newChildSeqs.flatten)
Shorthand for
withChildren(newChildSeqs.flatten)
- Definition Classes
- UpdatableElemLike → UpdatableElemApi
-
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
- Elem → UpdatableElemLike → UpdatableElemApi
-
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
- UpdatableElemLike → UpdatableElemApi
-
final
def
withUpdatedChildren(index: Int, newChild: ThisNode): ThisElem
Shorthand for
withChildren(children.updated(index, newChild))
Shorthand for
withChildren(children.updated(index, newChild))
- Definition Classes
- UpdatableElemLike → UpdatableElemApi