Skip to content

Improve xml.Attribute.copy and xml.MetaData.iterator #4050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scabug opened this issue Dec 2, 2010 · 2 comments
Closed

Improve xml.Attribute.copy and xml.MetaData.iterator #4050

scabug opened this issue Dec 2, 2010 · 2 comments

Comments

@scabug
Copy link

scabug commented Dec 2, 2010

= 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.

@scabug
Copy link
Author

scabug commented Dec 2, 2010

Imported From: https://issues.scala-lang.org/browse/SI-4050?orig=1
Reporter: Steven Bethard (bethard)

@scabug
Copy link
Author

scabug commented Jul 17, 2015

@SethTisue said:
The scala-xml library is now community-maintained. Issues with it are now tracked at https://github.com/scala/scala-xml/issues instead of here in the Scala JIRA.

Interested community members: if you consider this issue significant, feel free to open a new issue for it on GitHub, with links in both directions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant