Skip to content
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

Preserve attribute order && Keep Tags minimized #2735

Closed
scabug opened this issue Nov 30, 2009 · 11 comments
Closed

Preserve attribute order && Keep Tags minimized #2735

scabug opened this issue Nov 30, 2009 · 11 comments

Comments

@scabug
Copy link

scabug commented Nov 30, 2009

I have to automatically create a lot of JNDI environment variables like the following:

Now no matter what I do, Scala will always put the "name" attribute last, i.e. change attribute ordering and also expand my empty tag. I searched the mailing list for a solution to the expanding problem, but in Snapshot 2.8.0 there doesn't seem to be an easy one. The end result is this:

Now I'd love to have the attribute order preserved, as scanning variables (with my human eyes :) ) by the "name" attribute in a jndi config file is a very common thing to do. I can live with the tag expansion, even though it adds a bit of bloat and wonder why Scala expands my empty tag in the first place: I would write down the expanded version if I wanted to.

Thanks guys!

@scabug
Copy link
Author

scabug commented Nov 30, 2009

Imported From: https://issues.scala-lang.org/browse/SI-2735?orig=1
Reporter: behlma

@scabug
Copy link
Author

scabug commented Dec 15, 2010

Steven Bethard (bethard) said:
I just found a particularly nasty example of where not keeping tags minimized causes real problems. If I insert a "
" element in a HTML page, Scala expands that to "

" which is interpreted as two line breaks, not one, in both Firefox and Chrome.

@scabug
Copy link
Author

scabug commented Jul 28, 2011

Silvio Bierman (silviobierman) said:
I would love some information about the current state of this issue. My Scala world sort of revolves around XML documents, transforming XML into new XML or into HTML. I really need attribute ordering preservation desperately.

@scabug
Copy link
Author

scabug commented Jul 28, 2011

Steven Bethard (bethard) said:
I wonder if anti-xml (http://anti-xml.org/) has a fix for this problem? That seems to be much more active than whoever maintains scala.xml and they're even looking into supporting scala XML literals:

https://groups.google.com/d/topic/scala-internals/eoTgKU8MGo4/discussion

@scabug
Copy link
Author

scabug commented Jul 28, 2011

Silvio Bierman (silviobierman) said:
Anti-xml does not look to strive to backward compatibility so for my current projects I am afraid it is not an option. Is the XML handling by the compiler (literals, matching) pluggable at all?

To be honest, although the API is a bit odd at places scala.xml suits most of my needs. If only this issue would be fixed I would be quite happy to keep using it.

If I had to guess I would think it would take little more than replacing a HashMap with a LinkedHashMap or something like that. Is this issue currently assigned to anyone at all?

@scabug
Copy link
Author

scabug commented Jan 15, 2012

@khernyo said:
"Preserve attribute order" is done in current master. (scala/scala@126469f)

@scabug
Copy link
Author

scabug commented Jan 15, 2012

Steven Bethard (bethard) said:
Those changes look a little odd, in particular that some asserts in the tests have been replaced by printlns.

@scabug
Copy link
Author

scabug commented Jan 16, 2012

@khernyo said:
Those asserts were added by me a couple of days earlier when I didn't know about a nice partest feature. Printlns are better in this case because partest compares the output to the .check file and prints the difference if it doesn't match (this also means the test failed). It would be a bit more verbose to achieve the same using asserts.

So, the only real change in xml-attribute.scala is the last five lines.

@scabug
Copy link
Author

scabug commented Jan 16, 2012

Steven Bethard (bethard) said:
I see. Makes sense. Thanks for explaining!

@scabug
Copy link
Author

scabug commented Mar 19, 2012

@acruise said:
Was fixed in master a couple months ago, thanks Szabolcs! The change should ship in 2.10.

@scabug scabug closed this as completed Mar 19, 2012
@scabug
Copy link
Author

scabug commented Jul 18, 2013

David Portabella (dportabella) said:
"Preserve attribute order" is done in inline xml, but the following code does not preserve attribute order: xml.XML.save("out.xml", xml.XML.load("in.xml"))

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