- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
[scala-bts] #4050: Improve xml.Attribute.copy and xml.MetaData.iterator
Thu, 2010-12-02, 15:00
------------------------+---------------------------------------------------
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.
------------------------+---------------------------------------------------
Reporter: bethard | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: |
------------------------+---------------------------------------------------
Changes (by bethard):
* cc: steven.bethard@… (added)