-
Notifications
You must be signed in to change notification settings - Fork 92
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
XML parser reverses attribute order #65
Comments
Thanks Graeme for taking time to re-reporting this issue from scala JIRA. We are in the process of migrating all the open issues from JIRA to github. I have left my test work on the migration as comment so that community can review it. ( #62) Thanks again. |
If no one's picked this up yet, I'd be happy to take a wack at it. |
Glad that you would like to help. We will be more than happy if we can get some help from you. Please let me know if you need any help from me. Good luck. |
I wanted to comment on this issue. Technically, order of attributes is not significant in XML. A proper equality comparison of two XML objects would find them equal even if the attributes are in different orders. However, I understand the motivation for wanting to reduce deltas. The library shouldn't change things that don't need to be changed. A related issue is changes of namespace prefixes for attributes or elements. The actual prefixes used are part of the XML Infoset, so techically This suggests that there are really several different levels of equality and correspondingly preservation (which is what this issue is about).
|
@biswanaths Do I need to make a pull request out of my branch, or can the commit (only the 2nd one, sorry) get pulled in here as a first-class citizen by you (as the admin)? |
any updates on this pull request? |
What if you use ConstructingParser, is the order still scrambled? |
hey @SethTisue My file
This is how I am using it
What I get back?
On this other hand when I load the same file using
It seems to load it correctly
but semantically has different orders and removed comments as documented http://stackoverflow.com/questions/40941628/scala-loadfile-xml-reorders-original-xml-and-removes-comments any help resolving this is appreciated |
@hhimanshu I'm sorry but this is an issue tracker, not a support forum. if you have a question about ConstructingParser, ask on Stack Overflow. if you become convinced there is a bug in ConstructingParser, you can open a new issue here. |
Looks like Constructing Parser has the same issue. I'll add tests to the previous tests and make them in to a PR. |
I added the question on Stackoverflow. http://stackoverflow.com/questions/40942075/constructingparser-could-not-load-valid-xml-document-from-file Thanks |
I was able to use |
good to know, thanks @hhimanshu |
Shall I open a Scala Issue for that? |
for what? |
|
oh, I don't think we need a separate ticket for that, it's fine just as comments here on this one. |
ok Thanks |
I am thinking if there is anything I could do at the moment to unblock myself |
The other way (not the best way, but probably acceptable for my use case) is following
This is what I did
and on command-line, I see
|
The proposed fix in #172 also fixes |
New comment to scala-user on Aug-14-2017: http://www.scala-archive.org/Scala-XML-and-attribute-reordering-td3083550.html |
This issue is copied across from https://issues.scala-lang.org/browse/SI-6341
The original person who raised the issue attached a patch to add a failing test case.
When parsing XML and then writing it out again, the order of attributes is reversed.
This prevents certain use cases where one wants to modify an XML file and have a minimal amount of changes. E.g. adding a new element to a file causes all existing attributes to get reversed.
The cause is here:
https://github.com/scala/scala/blob/81e3121eb09010375783d13e8c4c853686a34ffd/src/library/scala/xml/parsing/MarkupParser.scala#L302
aMap: MetaData is built by prepending new attributes to the linked list, causing the reversal.
The attached patch adds a failing test case. (It failed when I wrote it originally, now I can't test it because the build fails).
commit 272ed40345c9f8f4af878f15299155cecfd8db2e
Author: Robin Stocker [email protected]
Date: Sat Sep 8 19:11:50 2012 +0200
diff --git a/test/files/run/xml-attribute-order-parse.check b/test/files/run/xml-attribute-order-parse.check
new file mode 100644
index 0000000..6637a4f
--- /dev/null
+++ b/test/files/run/xml-attribute-order-parse.check
@@ -0,0 +1 @@
+
diff --git a/test/files/run/xml-attribute-order-parse.scala b/test/files/run/xml-attribute-order-parse.scala
new file mode 100644
index 0000000..3be386c
--- /dev/null
+++ b/test/files/run/xml-attribute-order-parse.scala
@@ -0,0 +1,9 @@
+import xml.XML
+
+object Test {
+}
The text was updated successfully, but these errors were encountered: