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

[scala-bts] #2156: XML pattern matching with namespaces

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

-------------------------------------------+--------------------------------
Reporter: acruise | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: xml pattern matching namespace |
-------------------------------------------+--------------------------------
Scala supports pattern matching against XML nodes in only a very
rudimentary way. The lack of any support for namespaces may be the most
glaring omission.

http://www.nabble.com/Namespace-support-in-XML-patterns-td17562546.html
was a few years ago but had some fairly concrete suggestions, I'll write
up a pre-pre-SIP "hopefully soon" to try to move things along.

Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: [scala-bts] #2156: XML pattern matching with namespaces

-------------------------------------------+--------------------------------
Reporter: acruise | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: xml pattern matching namespace |
-------------------------------------------+--------------------------------

Comment(by acruise):

Note that I'm specifically talking about matching patterns with idiomatic
XML-like syntax, e.g.:
{{{
xml match {
case => ...
case { kids: _* } => ...
}
}}}

Of course, you can always match against scala.xml.Elem constructors but
that gets ugly fast.

Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: [scala-bts] #2156: XML pattern matching with namespaces

-------------------------------------------+--------------------------------
Reporter: acruise | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: xml pattern matching namespace |
-------------------------------------------+--------------------------------

Comment(by Juergen Purtz):

It seems that we speak about two different problems in this ticket:

No. 1: Pattern matching is not able to accept element names plus
attributes.
Test case:

{{{
val xml = some text
xml match {
// Next statement will not compile. Remove attribute and it will
// compile (2.7.7). Is the result correct (matching regardless of
attribute)?
case {content} => println(" match: " +
content)
case other => println("no match: " +
other)
}
}}}
This is first a problem of the compiler and second a possible problem of
undefined behaviour.

No.2: Namespace problems because of recognition only prefixes and not
URI's (as discussed by Stefan Zeiger and others in the link to
nabble.com).

Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: [scala-bts] #2156: XML pattern matching with namespaces

-------------------------------------------+--------------------------------
Reporter: acruise | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: xml pattern matching namespace |
-------------------------------------------+--------------------------------

Comment(by willisblackburn):

Has anything happened with this ticket? I am also frustrated by Scala's
poor support for XML namespaces. Scala makes it easy to implement
namespace-aware code the wrong way (by assigning meaning to the prefix)
and hard to implement it the right way (by assigning meaning to the
namespace URI). Ideally we should refactor the API so that it uses
namespaces almost exclusively. For example, instead of passing a prefix
to Elem, the code should pass a namespace URI, plus the namespace binding,
which is already part of the API. The prefix should only come into play
when a node is converted to or from a string.

I know that people are going to say that changing this will break code,
but I think that we need to think about the future. Scala is a young
language. There isn't that much code out there, and not all of it uses
the XML library. Scala's XML support is unique and is a major feature of
the language. It's better to take some lumps now and get it sorted out.

Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: [scala-bts] #2156: XML pattern matching with namespaces

-------------------------------------------+--------------------------------
Reporter: acruise | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: xml pattern matching namespace |
-------------------------------------------+--------------------------------

Comment(by willisblackburn):

By the way I'm happy to work on it. I'd need some guidance from someone
who was more familiar with the compiler but could take care of the code
changes myself. Email me at wboyce [at] panix [dot] com.

Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: [scala-bts] #2156: XML pattern matching with namespaces

-------------------------------------------+--------------------------------
Reporter: acruise | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Keywords: xml pattern matching namespace |
-------------------------------------------+--------------------------------
Changes (by willisblackburn):

* cc: wboyce@… (added)

Comment:

That's wboyce at panix dot com.

Scala 2
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: [scala-bts] #2156: XML pattern matching with namespaces

------------------------+---------------------------------------------------
Reporter: acruise | Owner: scala-xml_team
Type: enhancement | Status: new
Priority: normal | Component: XML support
Version: | Keywords: xml pattern matching namespace
------------------------+---------------------------------------------------
Changes (by extempore):

* cc: paulp@… (added)

Comment:

Replying to [comment:3 willisblackburn]:
> Has anything happened with this ticket?

By observation I am the only one who has addressed XML bugs in recent
times, and I'm definitely not working on this one. It's fine to say we
should break the API and rewrite things to be better -- I totally agree --
it's a ton of work (not just technical, also you have to convince other
people) and I'm not personally interested in XML so I won't be doing that
work.

Nothing would make me happier than to see someone else do that work, but
don't imagine it's a matter of dashing off something which seems more
sensible. You will have to effectively champion your code. And don't
think you can get into breaking changes without taking on at least a few
of the zillions of other issues people raise from time to time (see recent
scala-xml traffic for some examples.)

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