This page is no longer maintained — Please continue to the home page at www.scala-lang.org

[scala-bts] #4050: Improve xml.Attribute.copy and xml.MetaData.iterator

1 reply
Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.

------------------------+---------------------------------------------------
Reporter: bethard | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: |
------------------------+---------------------------------------------------
= problem =
When transforming XML, it is often necessary to transform attribute values
as well as elements. It would be nice to be able to write something like:

{{{
case elem: Elem => elem.copy(attributes=
for (attr <- elem.attributes) yield attr match {
case attr@Attribute("attrToChange", _, _) =>
attr.copy(value=Text("newValue"))
case other => other
}
)
}}}

= analysis =

This doesn't work in Scala 2.8.1 because {{{xml.Attribute.copy}}} only
allows the {{{next}}} attribute to be changed, and because map over an
{{{xml.MetaData}}} yields an {{{Iterable[MetaData]}}} not a
{{{MetaData}}}.

= enhancement recommendation =

To solve the copying problem, {{{xml.Attribute}}} could grow a method like
one of the {{{xml.Attribute.apply}}} methods, e.g.:

{{{
def copy(pre: String = this.pre, key: String = this.key, value: Seq[Node]
= this.value, next: MetaData = this.next): Attribute
}}}

Solving the map problem probably means updating {{{Attribute}}} to use the
new collections APIs better - e.g. it should probably implement
{{{IterableLike[MetaData, MetaData]}}} which I think means it needs a
simple {{{Builder}}} that sets the {{{next}}} attributes appropriately.

Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: [scala-bts] #4050: Improve xml.Attribute.copy and xml.MetaDa

------------------------+---------------------------------------------------
Reporter: bethard | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: |
------------------------+---------------------------------------------------
Changes (by bethard):

* cc: steven.bethard@… (added)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland