Git Product home page Git Product logo

Comments (7)

ScalaWilliam avatar ScalaWilliam commented on August 16, 2024
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.

fancellu avatar fancellu commented on August 16, 2024

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.

ScalaWilliam avatar ScalaWilliam commented on August 16, 2024
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.

ScalaWilliam avatar ScalaWilliam commented on August 16, 2024
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.

fancellu avatar fancellu commented on August 16, 2024
   <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.

HuStmpHrrr avatar HuStmpHrrr commented on August 16, 2024

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.

SethTisue avatar SethTisue commented on August 16, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.