Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 17 06:14
    sjrd commented #533
  • Jun 17 04:52
    julienrf commented #533
  • Jun 16 20:10
    SethTisue commented #533
  • Jun 16 04:32
    SethTisue commented #526
  • Jun 16 04:32
    SethTisue closed #526
  • Jun 14 15:54

    SethTisue on main

    Update sbt to 1.5.4 (#535) (compare)

  • Jun 14 15:54
    SethTisue closed #535
  • Jun 14 15:48
    SethTisue assigned #526
  • Jun 14 15:25
    ashawley commented #526
  • Jun 14 07:02
    scala-steward opened #535
  • Jun 09 06:51
    scala-steward synchronize #533
  • Jun 09 04:43

    SethTisue on main

    Update scala-compiler, scala-li… (compare)

  • Jun 09 04:43
    SethTisue closed #530
  • Jun 08 19:15
    scala-steward opened #534
  • Jun 08 17:55
    SethTisue commented #526
  • Jun 08 17:20
    scala-steward opened #533
  • Jun 08 08:56
    david-bouyssie commented #282
  • Jun 01 16:35
    mbeckerle commented #508
  • Jun 01 16:30
    mbeckerle commented #508
  • Jun 01 16:29
    mbeckerle opened #532
aappddeevv
@aappddeevv
I just saw that. I'm thinking that once dotty switches to the 2.13 stdlib that this is where there may be a problem unless scala-xml is republished under 2.13--if I read your comment right.
That could happen in as little as 30 days if they keep publishing RC releases each month.
Seth Tisue
@SethTisue
@aappddeevv scala-xml is already published for 2.13
aappddeevv
@aappddeevv
Ah..that's right...I'm getting a transitive dependency that pushes it back to a 2.12 version though for this dotty project. I guess I'll wait and see what happens to that lib and the xml dependency once the dotty stdlib is updated..
Seth Tisue
@SethTisue
:+1:
Aaron S. Hawley
@ashawley
Indeed, seems you need to use the sbt-dotty plugin and 2.12 artifacts to work with dependencies from dotty
I've made some changes to the old scala modules sample repo to show that it works
Mohamedali10
@Mohamedali10
Hello @all, I'am trying to create a large XML file that contains data retrieved from data base, for that I do not want to hold the whole xml in memory but instead I want to write it directly in the disk, any recommendation on implementing this please?
Seth Tisue
@SethTisue
@Mohamedali10 the scala-xml library probably won't be useful to you here, it's designed for in-memory applications. (there's scala.xml.pull, but it's deprecated, for good reasons.) I'd suggest looking into what Java XML libraries support streaming, and use one of those from Scala
Mohamedali10
@Mohamedali10
@SethTisue thanks
Mohamedali10
@Mohamedali10

Hello, @all I would like to write an xml Elem to a file, but I want to set the line separator between each node of the elem, so when opening the file under windows or ubuntu I have the correct format. for example :

val lineSep = System.getProperty("line.separator") 
val xmlData : Elem = <person>
       <firstName>John</firstName>
       <lastName>Doe</lastName>
  <emails>
  <email type=”primary”>john.doe@noone.com</email>
  <email type=”secondary”>john.doe@noone.com</email>
  </emails>
  <address>
  <street>595 Market Street</street>
  <city>San Francisco</city>
  <zip>94105</zip>
  </address>
  </person>

How to write it into a file and considering the lineSep?

Seth Tisue
@SethTisue
(we're discussing this in scala/scala. @Mohamedali10 when you ask the same question in more than one place on the internet, it's polite to mention that fact, so that someone doesn't waste time helping you in one place, if you already got helped in the other place)
Mohamedali10
@Mohamedali10
@SethTisue ok I'am just lookig for better answers thanks
Francois Armand
@fanf

I see the following change in behavior between scala 2.12 and 2.13:
scala 2.12:

scala> import scala.xml._
import scala.xml._

scala> val a: NodeSeq = <a>Hello</a>
a: scala.xml.NodeSeq = <a>Hello</a>

scala> a ++ <b>hi</b>
res0: scala.xml.NodeSeq = NodeSeq(<a>Hello</a>, <b>hi</b>)

Scala 2.13:

scala> a ++ <b>hi</b>
res0: Seq[scala.xml.Node] = List(<a>Hello</a>, <b>hi</b>)

That change has a very deep reach for us, because Lift doesn't interpret both type in the same way: it applies template transformation one time for a NodeSeq (it's only one template), and N times for List[Node] (it's a list of template). Our web application is totally broken, and it's almost impossible to find all places which would need a type ascription (and it would bloat a lot the resulting code.

Is there a way to get back the old behavior? Perhaps we are missing a new implicit? Perhaps the implicit precedence in NodeSeq changed and it could be adpated?
Any insight would be appreciated.

(reposting here from scala/scala, seems more appropriate, I wasn't aware of the existence of that chan)
Seth Tisue
@SethTisue
(in the other room, I suggested opening a ticket in the scala-xml repo)
Francois Armand
@fanf
thanks @SethTisue , will do so, I wanted to have a feedback from here before opening ticket
Francois Armand
@fanf
for record: scala/scala-xml#392
David Geirola
@geirolz

Hi guys, i have a question for you. I'm trying to map Elem children but the result is not what i expected.

val elem: Elem =
      <a>
        <b>1</b>
        <b>2</b>
        <b>3</b>
      </a>

    val result = elem.child.map(k => <c>{k.text}</c>)

Returns

ArrayBuffer(
               <c></c>,
                <c>1</c>,
                <c></c>,
                <c>2</c>,
                <c></c>,
                <c>3</c>,
                <c></c>
    )

Can someone explain me why this happend ? why empty nodes ?

Aaron S. Hawley
@ashawley
The whitespace between the elements is part of the structure.
elem.child.map { 
  case e: Elem => <c>k.text</c>
  case n => n
}
res0: Seq[scala.xml.Node] = List( , <c>k.text</c>,  , <c>k.text</c>,  , <c>k.text</c>,  )
David Geirola
@geirolz
Ok, now it's clear, thank you
Fabian Schüssler
@FabianSchuessler
Hi, how can I change the attribute of a node?
elem \@ "src" = "shouldBeNewValue"
Chris Coppins
@st900_gitlab
Hi everyone, I this might be related to @fanf's point, but how do I prepend an optional element with the result being itself XML i.e. {if (mycondition) { <td> hello </td>} else xml.NodeSeq.Empty} ?? <td> bob </td>
Aaron S. Hawley
@ashawley
@st900_gitlab
scala> <table>{ <td>world</td>.prepended(if (true) { <td>hello</td> } else { NodeSeq.Empty }) }</table>
res0: scala.xml.Elem = <table><td>hello</td><td>world</td></table>
Chris Coppins
@st900_gitlab
@ashawley thanks
Mohamedali10
@Mohamedali10
Hi, suppose that I have the following xml Elem, and I want to convert it into a String in a specific encoding. Is it possible to do that ?
<person id ="1"> 
<name> person1</name>
<age>20</age>
<address> address</address>
</person>
ritschwumm
@ritschwumm
@Mohamedali10 since a string by itself always is (kindof) UTF-16, i guess what you need is a sequence of bytes? in which encoding?
Matt Hughes
@matthughes
Can someone confirm what the latest stable release compatible with 2.13 is? Github project page and releases page are confusing me a bit.
Releases seems to think 1.3.0 is latest and greatest, released on March 16 with 2.0.0M1 being released on Feb 5th.
Aaron S. Hawley
@ashawley
@matthughes Yes, 1.3.0 is the latest stable release. 2.0.0-M1 is unstable.
Matt Hughes
@matthughes
Thanks
Mohamedali10
@Mohamedali10
Hi, is it possible to determine the encoding of an Elem that I read from a file?
Aaron S. Hawley
@ashawley
@Mohamedali10 No, I don't believe the file encoding is an attribute of an Elem. There are a few file-related functions in scala-xml, so there is an encoding setting , but that won't help. The XML declaration could have an encoding attribute, or not, but I don't think that's tracked either. Parts of the code look like there was an effort to try and capture the encoding, but it was abandoned and never completed.
Mohamedali10
@Mohamedali10
thanks @ashawley
hagaiy
@hagaiy
hello is there an xxe filter for that ?
kumaranae
@kumaranae
@here.. I am using Scala 2.9.3 and hitting the scala/scala-xml#125 BasicTransformer exponential complexity issue. I am not in the position to upgrade my scala version to the latest. is there any other way i can fix the issue?
Aaron S. Hawley
@ashawley
@kumaranae I don't believe there is a way, no. In Scala 2.9, the XML support is part of the Scala standard library. There were never artifacts of scala-xml produced for Scala 2.9. You would probably have to build the standard library and backport the fix.
peterlopen
@peterlopen
hi, please, could someone explain what is wrong with my setup? trying to use scala-xml in sbt dotty (3.0.0-RC1) project. dependency "org.scala-lang.modules" %% "scala-xml" % "2.0.0-M5" was found, however packages in scala-xml do not contain any classes. tried both 2.0.0-RC1 and 2.0.0-M5 versions.
Aaron S. Hawley
@ashawley
@peterlopen Looks like the JAR has class files to me. https://repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_3.0.0-RC1/2.0.0-RC1/
shvahabi
@shvahabi:matrix.org
[m]

Is xml string interpolation implemented as a feature of Scala 3 ? If positive, how can I make

xml"""
         |<p>Hello World!</p>
         |""".stripMargin

compile? I always receive a value xml is not a member of StringContext error message.

Aaron S. Hawley
@ashawley
@shvahabi:matrix.org There was a proposal to add an xml interpolator, but I don't think it was published. https://github.com/lampepfl/xml-interpolator
1 reply
mvillafuertem
@mvillafuertem

Hi there,

Parse XML using Scala with colon (:) inside XML tag. is this possible?

  val xml =
    """
      |<saml2p:Response Version="2.0" xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol">
      |    <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
      |        https://metadata
      |    </saml2:Issuer>
      |</saml2p:Response>
      |""".stripMargin

  val doc = scala.xml.XML.loadString(xml)

  val node = (doc \ "Issuer")
  println(node)
  println(node \@("saml2"))
  println(doc \@("xmlns"))
I want extract the attribute xmlns:saml2, but I don't get result :(
Aaron S. Hawley
@ashawley
@mvillafuertem Yeah, this is a complicated example, so the scala-xml documentation doesn't offer much help. That is the namespace you're trying to extract, so it's not an attribute, and as you found out the \ operator only works by element label, and not prefix, and the same for \@.
scala> doc.label
val res0: String = Response

scala> doc.prefix
val res1: String = saml2p

scala> doc.attributes
val res2: scala.xml.MetaData =  Version="2.0"

scala> doc.namespace
val res3: String = urn:oasis:names:tc:SAML:2.0:protocol

scala> doc \@ "Version"
val res4: String = 2.0

scala> val nodes = (doc \ "Issuer")
val nodes: scala.xml.NodeSeq = ...

scala> nodes.map(elem => (elem.namespace, elem.label, elem.text.trim))
val res5: Seq[(String, String, String)] = List((urn:oasis:names:tc:SAML:2.0:assertion,Issuer,https://metadata))
mvillafuertem
@mvillafuertem
@ashawley Thanks a lot
Seth Tisue
@SethTisue

THIS ROOM IS CLOSED