Comments (22)
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.
from scala-xml.
If no one's picked this up yet, I'd be happy to take a wack at it.
from scala-xml.
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.
from scala-xml.
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 <a:b xmlns:a="urn:foo"/>
is not always equal to <c:b xmlns:c="urn:foo"/>
because their infoset contents are different. XML is allowed to be sensitive to the specific characters used in the prefixes of the QNames.
This suggests that there are really several different levels of equality and correspondingly preservation (which is what this issue is about).
- preserve order of attributes (and do comparison/equality where order of attributes matters)
- preserve XML infoset (and equality where everything about XML infoset is compared, and only that - so attribute order doesn't matter, but specific prefix characters do matter)
- preserve XML namespace-aware infoset (and equality where namespace prefixes are interpreted as their namespaces and the specific characters of the prefix are disregarded, and attribute order doesn't matter)
from scala-xml.
@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)?
from scala-xml.
any updates on this pull request?
from scala-xml.
What if you use ConstructingParser, is the order still scrambled?
from scala-xml.
hey @SethTisue
I guess I am not able to load my document using ConsructingParser
My file
$cat /tmp/person.xml
<root xmlns="http://www.nyorg.com/metadata/config" xmlns:core="http://www.myorg.com/metadata/commonschematypes" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xschema/AppConfig.xsd">
<!-- This is important comment about person-->
<person>
<firstName>John</firstName>
<lastName>Doe</lastName>
<email>[email protected]</email>
<city>SomeWhere</city>
<property name="myName" value="someValue" />
</person>
</root>
This is how I am using it
val source = io.Source.fromURL(new java.io.File("/tmp/person.xml").toURL)
val d = scala.xml.parsing.ConstructingParser.fromSource(source, preserveWS = true)
val doc = d.document()
println(doc)
What I get back?
:1:1: < expected<root xmlns="http://www.nyorg.com/metadata/config" xmlns:core="http://www.myorg.com/metadata/commonschematypes" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xschema/AppConfig.xsd">^
doc: scala.xml.Document = null
null
On this other hand when I load the same file using XML.loadFile
as
val doc = XML.loadFile("/tmp/person.xml")
println(doc)
It seems to load it correctly
<root xsi:noNamespaceSchemaLocation="../xschema/AppConfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:core="http://www.myorg.com/metadata/commonschematypes" xmlns="http://www.nyorg.com/metadata/config">
<person>
<firstName>John</firstName>
<lastName>Doe</lastName>
<email>[email protected]</email>
<city>SomeWhere</city>
<property value="someValue" name="myName"/>
</person>
</root>
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
from scala-xml.
@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.
from scala-xml.
Looks like Constructing Parser has the same issue. I'll add tests to the previous tests and make them in to a PR.
from scala-xml.
I added the question on Stackoverflow. http://stackoverflow.com/questions/40942075/constructingparser-could-not-load-valid-xml-document-from-file
Thanks
from scala-xml.
I was able to use ConstructingParser
, but I can prove that even ConstructingParser
reorders attributes. For details, see http://stackoverflow.com/a/40942534/379235
from scala-xml.
good to know, thanks @hhimanshu
from scala-xml.
Shall I open a Scala Issue for that?
from scala-xml.
Shall I open a Scala Issue for that?
for what?
from scala-xml.
ConstructingParser
not preserving the order of element attributes
from scala-xml.
oh, I don't think we need a separate ticket for that, it's fine just as comments here on this one.
from scala-xml.
ok Thanks
from scala-xml.
I am thinking if there is anything I could do at the moment to unblock myself
from scala-xml.
The other way (not the best way, but probably acceptable for my use case) is following
- Load the XML (using
ConstructingParser
) - Perform Manipulation(s)
- f1 = Persist XML (intermediate representation with reversed attributes)
- Load the XML (using
ConstructingParser
) - f1 = persist XML (final representation)
This is what I did
import scala.xml._
import java.io.File
import scala.xml.parsing.ConstructingParser
val path = "/tmp/"
val filePath = path + "person.xml"
val newFilePath = path + "person.intermediate.xml"
val finalFilePath = path + "person.final.xml"
val source = io.Source.fromURL(new File(filePath).toURL)
val cp = ConstructingParser.fromSource(source, true)
XML.save(newFilePath, cp.document().head)
val source1 = io.Source.fromURL(new File(newFilePath).toURL)
val cp1 = ConstructingParser.fromSource(source1, true)
XML.save(finalFilePath, cp1.document().head)
and on command-line, I see
$ /tmp cat person.xml; echo "----------"; cat person.final.xml
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<!-- This is important comment -->
<person>
<fName>John</fName>
<lName>Doe</lName>
<property name="someName" value="someValue">p1</property>
</person>
</root>
----------
<root>
<!-- This is important comment -->
<person>
<fName>John</fName>
<lName>Doe</lName>
<property name="someName" value="someValue">p1</property>
</person>
</root>
from scala-xml.
I was able to use
ConstructingParser
, but I can prove that evenConstructingParser
reorders attributes.
The proposed fix in #172 also fixes ConstructingParser
as well.
from scala-xml.
New comment to scala-user on Aug-14-2017:
http://www.scala-archive.org/Scala-XML-and-attribute-reordering-td3083550.html
from scala-xml.
Related Issues (20)
- Update CHANGELOG.md HOT 2
- Shut down Gitter room, enable GitHub Discussions? HOT 4
- CDATA in MarkupParser HOT 3
- ConstructingParser does not tolerate start of file whitespace HOT 1
- ConstructingParser throws NoSuchMethodError in Scala 3 HOT 6
- Release 2.0.1
- versionPolicyCheck fails for scalajs-library HOT 4
- ""
- Publish next release (to publish Scala 3 Native support) HOT 15
- Version 2.10 null pointer on toString
- Name predicates: which XML version? HOT 2
- Re-enable versionPolicyCheck HOT 2
- Update CHANGELOG, README? HOT 1
- Drop support for Scala 2.11? HOT 5
- Unused value warnings for XML literals starting with Scala 2.13.9 HOT 1
- Infinite loop caused by mismatched quotes HOT 3
- Roll a 2.2 release HOT 5
- Release 1.3.1 HOT 10
- FactoryAdapter loadDocument() modifies XMLReader and breaks it HOT 4
- Publish an artifacts for Scala-Native-0.5.0-RC2 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scala-xml.