Comments (7)
scala> val a = <number>{2}</number>
a: scala.xml.Elem = <number>2</number>
scala> val b = <number>2</number>
b: scala.xml.Elem = <number>2</number>
scala> a == b
res0: Boolean = false
scala> (a.hashCode, b.hashCode)
res0: (Int, Int) = (-1257096872,361570984)
from scala-xml.
Thanks William, back to my version, you can "fix" by stringifying then loading back. Ha! (I'm cringing)
(scala.xml.XML.loadString(root2.toString) "number").filter(find2)
So that is why when you're getting your XML from a string/url/file/dom, it will be fine, its just the Scala escaped stuff which seems broken.
Or. generate like this:
val root2=
{for (x<- 1 to 3) yield {scala.xml.Text(x.toString)}}
{x} emits an Atom. But renders the same. Either way, it doesn't follow the principle of least surprise
from scala-xml.
package com.scalawilliam.examples
object Equality extends App {
val a = <number>{2}</number>
val b = <number>2</number>
println(a.xml_==(b))
println(a.equals(b))
println(a == b)
println((<numbers><number>{2}</number><number>2</number></numbers> \ "number").distinct)
}
false
false
Set(<number>2</number>, <number>2</number>)
from scala-xml.
package com.scalawilliam.examples
object Equality extends App {
val number = <numbers><number>{2}</number><number>2</number></numbers> \ "number"
val numbers = for {
item <- number
i <- item
j <- i
node <- j.child
} yield (node, node.hashCode(), node.getClass.getName, node.map(_.asInstanceOf[scala.xml.Atom[_]].data.getClass.getName))
numbers foreach println
}
(2,-548373507,scala.xml.Atom,List(java.lang.Integer))
(2,-301266488,scala.xml.Text,List(java.lang.String))
from scala-xml.
<node>{2}</node> == <node>2</node>
> false
<node>{Text(2.toString)}</node> == <node>2</node>
> true
<node>{2}</node> == <node>{2}</node>
>true
So if using XML literals and curly braces to inject values, best test against similar escaped value, and not what looks the same when serialized.
from scala-xml.
get caught by it.
ant chance to fix it? it's too surprising. i was wondering what happened and spent 1-2 hrs on this.
from scala-xml.
@HuStmpHrrr pull request welcome. this repo is community-maintained, the only fixes coming in these days are coming from the community.
from scala-xml.
Related Issues (20)
- Publish 2.0.0 HOT 1
- 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
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.