Scala XML and attribute reordering

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Scala XML and attribute reordering

Silvio Bierman
I know this has been discussed several times but I have no clear picture of what the consensus on the issue is.

I am stumbling once again over this weird library behavior. My application presents information from an XML document to be edited by a user. Attribute presence is mainly static (no attributes are added or removed) but attribute values may change.

My first problem is that the XML documents are also read by human beings and they are really annoyed if the attribute ordering changes in counter-intuitive ways. I know that formally attribute ordering is of no importance but for a human reader this is not at all true.

The second and bigger problem is that the process that has to be triggered when the XML changes is quite expensive and temporarily disrupts (suspends) some server activity. Since the document is opened frequently but actually changed very infrequently I would really like to be able to compare the original XML document with the one coming out of the UI to determine if anything has changed. This currently sets false flags because of the reordering of attributes.

Is there any chance the library will be fixed in this area? If not, does anyone have tips on how to handle this situation?
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Vincent Pazeller-2

On 11 déc. 2010, at 19:03, Silvio Bierman <[hidden email]> wrote:

I know this has been discussed several times but I have no clear picture of what the consensus on the issue is.

I am stumbling once again over this weird library behavior. My application presents information from an XML document to be edited by a user. Attribute presence is mainly static (no attributes are added or removed) but attribute values may change.

My first problem is that the XML documents are also read by human beings and they are really annoyed if the attribute ordering changes in counter-intuitive ways. I know that formally attribute ordering is of no importance but for a human reader this is not at all true.

I agree... This is quite an odd behavior...
I don't know this library very well but this might have been done to improve attributes access ...


The second and bigger problem is that the process that has to be triggered when the XML changes is quite expensive and temporarily disrupts (suspends) some server activity. Since the document is opened frequently but actually changed very infrequently I would really like to be able to compare the original XML document with the one coming out of the UI to determine if anything has changed. This currently sets false flags because of the reordering of attributes.

Is there any chance the library will be fixed in this area? If not, does anyone have tips on how to handle this situation?

I see two ways to handle this:

- the first is easy to implement but not very elegant : instead of comparing your new document with the original one, you may first read and save the original document... So attributes will be reordered in both documents. This works if attributes reordering is deterministic.

- second option: you may write a wrapper around the library so that it behaves the way you like...


View this message in context: Scala XML and attribute reordering
Sent from the Scala - User mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Paul Phillips-3
In reply to this post by Silvio Bierman
On Sat, Dec 11, 2010 at 10:03:19AM -0800, Silvio Bierman wrote:
> My first problem is that the XML documents are also read by human
> beings and they are really annoyed if the attribute ordering changes
> in counter-intuitive ways. I know that formally attribute ordering is
> of no importance but for a human reader this is not at all true.

I think it's horrible that it doesn't preserve attribute ordering, but
the last time xml was discussed I was informed by people who care about
xml that fixing it would be some kind of crime against the way xml is
supposed to work.  The attitude on display mostly served to convince me
that xml is something best left to others.  (I'm sure you can google up
these discussions.) But I only worked on xml because there was nobody
else to do it, and there still isn't: so the others to whom I have left
it may be those from the movie "The Others".

--
Paul Phillips      | You think you know when you learn, are more sure
Apatheist          | when you can write, even more when you can teach,
Empiricist         | but certain when you can program.  -- Alan Perlis
i pull his palp!   |----------* http://www.improving.org/paulp/ *----------
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Robert Wills-2
In reply to this post by Vincent Pazeller-2
> - the first is easy to implement but not very elegant : instead of comparing
> your new document with the original one, you may first read and save the
> original document... So attributes will be reordered in both documents. This
> works if attributes reordering is deterministic.

Unfortunately, it appears that this is not the case:

scala> val loaded = XML.loadString("""<test c="333" d="123" a="foo"
b="bar"/>""")
loaded: scala.xml.Elem = <test b="bar" a="foo" d="123" c="333"></test>

scala> loaded == XML.loadString(loaded.toString)
res6: Boolean = false

scala> XML.loadString(loaded.toString)
res7: scala.xml.Elem = <test c="333" d="123" a="foo" b="bar"></test>

Very annoying.

There are some xml diffing tools out there: eg
http://diffxml.sourceforge.net/downloads.html
You might have some luck with one of those.
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Robert Wills-2
In reply to this post by Paul Phillips-3
> I think it's horrible that it doesn't preserve attribute ordering, but
> the last time xml was discussed I was informed by people who care about
> xml that fixing it would be some kind of crime against the way xml is
> supposed to work.  The attitude on display mostly served to convince me
> that xml is something best left to others.  (I'm sure you can google up
> these discussions.) But I only worked on xml because there was nobody
> else to do it, and there still isn't: so the others to whom I have left
> it may be those from the movie "The Others".
>

When I first came to Scala I thought its xml library was one of the
main attractions.
I now think that this was partly because after dealing with Java's xml libraries
anything would have seemed better and also that it was partly just the
syntactic
sugar of being able to put xml directly in your code that attracted me.

It does now seem to me (and from what I've seen to quite a few others)
that scala.xml
is a little clunky.  I don't understand why MetaData isn't a subclass
of Node.  It strikes me
that the data model of the Haskell HXT library would be a good place
to start doing an
alternative xml library: it treats xml as just a rose tree of nodes.
http://www.haskell.org/haskellwiki/HXT#The_basic_data_structures
I believe with  that sort of structure attributes would not be reordered.

Just some thoughts -- time for supper :).

-Rob
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Silvio Bierman
In reply to this post by Paul Phillips-3
Yep, I have watched that movie many times.

By supporting XML literals (which I think was done quite good) I think Scala created the expectation that it considers the XML library as a whole (as opposed to only some literal syntax) as a primary focus. It has been quite disappointing to see that the library was left in a "not quite finished" state.

The attribute reordering issue seems extra silly since it looks like it is a minor detail like storing them in a HashMap which can not preserve ordering. I suspect (without having looked at the actual sources) that simply replacing a HashMap with a LinkedHashMap might do wonders here.

The fact that nobody seems to be up to date with the library does not give me much hope that this may be fixed any time soon...
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Naftoli Gugenheim
Has anyone submitted a patch?


On Sun, Dec 12, 2010 at 2:35 PM, Silvio Bierman <[hidden email]> wrote:
Yep, I have watched that movie many times.

By supporting XML literals (which I think was done quite good) I think Scala created the expectation that it considers the XML library as a whole (as opposed to only some literal syntax) as a primary focus. It has been quite disappointing to see that the library was left in a "not quite finished" state.

The attribute reordering issue seems extra silly since it looks like it is a minor detail like storing them in a HashMap which can not preserve ordering. I suspect (without having looked at the actual sources) that simply replacing a HashMap with a LinkedHashMap might do wonders here.

The fact that nobody seems to be up to date with the library does not give me much hope that this may be fixed any time soon...

View this message in context: Re: Scala XML and attribute reordering

Sent from the Scala - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Paul Phillips-3
In reply to this post by Silvio Bierman
On Sun, Dec 12, 2010 at 11:35:56AM -0800, Silvio Bierman wrote:
> The attribute reordering issue seems extra silly since it looks like
> it is a minor detail like storing them in a HashMap which can not
> preserve ordering. I suspect (without having looked at the actual
> sources) that simply replacing a HashMap with a LinkedHashMap might do
> wonders here.

I could fix it in a matter of minutes.  It's not the technical
challenge, but an unwillingness to fade the static.  In fact it was
pointedly suggested that someone who didn't love XML the way it's
supposed to be loved (as I obviously do not) shouldn't be working on it.  
Seeing as it's unappealing work anyway, I was easily convinced.

--
Paul Phillips      | You think you know when you learn, are more sure
Imperfectionist    | when you can write, even more when you can teach,
Empiricist         | but certain when you can program.  -- Alan Perlis
pull his pi pal!   |----------* http://www.improving.org/paulp/ *----------
dpp
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

dpp


On Sun, Dec 12, 2010 at 11:49 AM, Paul Phillips <[hidden email]> wrote:
On Sun, Dec 12, 2010 at 11:35:56AM -0800, Silvio Bierman wrote:
> The attribute reordering issue seems extra silly since it looks like
> it is a minor detail like storing them in a HashMap which can not
> preserve ordering. I suspect (without having looked at the actual
> sources) that simply replacing a HashMap with a LinkedHashMap might do
> wonders here.

I could fix it in a matter of minutes.  It's not the technical
challenge, but an unwillingness to fade the static.  In fact it was
pointedly suggested that someone who didn't love XML the way it's
supposed to be loved (as I obviously do not) shouldn't be working on it.
Seeing as it's unappealing work anyway, I was easily convinced.

When the issue was raised prior to the 2.8 release, the consensus was reached that even though the current XML implementation is less than optimal, the cost of "doing it right" and the inability to find an owner or even get people to agree on stuff meant that the current XML implementation would live on for the foreseeable future.

There are two issues with improving the XML support in Scala: the library and the compiler piece.

The library is easy.  Nobody is stopping anyone from stepping up and writing a better library.  I know that my XML improvements were happily accepted into the Scala distribution.  If someone comes up with a better XML library for Scala, by all means, put it up on Scala-tools.org.  If it totally rocks, I'd be willing to use it in Lift instead of the Scala XML library.

The XML constants in the language are the larger issue.  But if someone solves #1 first, then this issue should be a smaller hurdle that could initially be solved with a compiler plugin.

With all this being said, representing one of the largest user-bases that relies on Scala's XML library (Lift), it's not so bad for us that it's worth writing a new set of XML classes.  Maybe that's true for another constituency, but my guess is that until someone ponies up actual code, we've got what we've got which isn't perfect, but it's serviceable.

 

--
Paul Phillips      | You think you know when you learn, are more sure
Imperfectionist    | when you can write, even more when you can teach,
Empiricist         | but certain when you can program.  -- Alan Perlis
pull his pi pal!   |----------* http://www.improving.org/paulp/ *----------



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Robert Wills-2
In reply to this post by Paul Phillips-3
Well if it can be easily fixed I think most Scala users would be
grateful for a change
which allowed for reliable round-tripping from text to xml asts and
back again.  If that
means that we don't love xml the way it's supposed to be loved then so be it.

On Sun, Dec 12, 2010 at 7:49 PM, Paul Phillips <[hidden email]> wrote:

> On Sun, Dec 12, 2010 at 11:35:56AM -0800, Silvio Bierman wrote:
>> The attribute reordering issue seems extra silly since it looks like
>> it is a minor detail like storing them in a HashMap which can not
>> preserve ordering. I suspect (without having looked at the actual
>> sources) that simply replacing a HashMap with a LinkedHashMap might do
>> wonders here.
>
> I could fix it in a matter of minutes.  It's not the technical
> challenge, but an unwillingness to fade the static.  In fact it was
> pointedly suggested that someone who didn't love XML the way it's
> supposed to be loved (as I obviously do not) shouldn't be working on it.
> Seeing as it's unappealing work anyway, I was easily convinced.
>
> --
> Paul Phillips      | You think you know when you learn, are more sure
> Imperfectionist    | when you can write, even more when you can teach,
> Empiricist         | but certain when you can program.  -- Alan Perlis
> pull his pi pal!   |----------* http://www.improving.org/paulp/ *----------
>
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Silvio Bierman
+1

I can think of numerous ways the library could be improved but IMHO its primary function is representing XML values and transforming these to and from textual representations. If that works then I can cook the more advanced stuff on top of that myself.
Reply | Threaded
Open this post in threaded view
|

Re: Scala XML and attribute reordering

Andrew
This post has NOT been accepted by the mailing list yet.
bump

this is a pain when trying to rewrite a legacy xml composer from a different language. You'd like to have the flexibility where you have the ability to specify the order of attributes in the same order of the legacy composer. That way you can verify the accuracy of the new xml compositions compared to the legacy composition.

certainly this must be a common use case of using the XML library