Questions tagged [scala-xml]

Scala XML is the standard XML library built for Scala.

Scala XML is the standard XML library built for Scala. It provides options for working with XML documents - parsing, processing, building, manipulating and navigating within, and others. Since Scala version 2.11, the Scala XML is a separate, independent library.

63 questions
42
votes
1 answer

scala String to scala.xml.Elem

I have to convert a string into XML scala> val string="" string: String = scala> val xml=() xml: scala.xml.Elem =
Govind Singh
  • 15,282
  • 14
  • 72
  • 106
14
votes
2 answers

Variable in CDATA in Scala

Is there a way to put a variable to be expanded in a cdata section in scala val reason =
maxfridbe
  • 5,872
  • 10
  • 58
  • 80
11
votes
1 answer

How to use Scala XML with Apache Flink?

I am trying to use Scala XML library in Flink to parse an XML and I am not able to make it work. Please note that I need to use both the serialized and unserialized (string) version on my code in the same processing function. I tried already…
Jac
  • 531
  • 1
  • 4
  • 19
10
votes
4 answers

How to track the source line (location) of an XML element?

I assume that there is probably no satisfactory answer to this question, but I ask it anyway in case I missed something. Basically, I want to find out the line in the source document from which a certain XML element originated, given the element…
Madoc
  • 5,841
  • 4
  • 25
  • 38
9
votes
2 answers

Select all child elements of a node in scala

I want to select the first child Elem of a Node named "a". What I've got now is: (xml \ "a")(0).child.collect {case e: Elem => e} This is quite verbose. I was looking for something like: xml \ "a" \ "*" Is this possible in scala?
Daniel Seidewitz
  • 720
  • 8
  • 23
8
votes
2 answers

Matching XML Literals in Scala Macros

I want to transform Scala XML literals with a macro. (Not a string literal with XML but actual XML literals). As far as I understand, XML literals are not actually built into the language on the AST level but are desugared in the parser.…
Martin Ring
  • 5,404
  • 24
  • 47
4
votes
2 answers

Best way to extract a node and all of its children using scala.xml.pull?

I'm using scala.xml.pull to parse through a vary large xml file. This works great for event processing, but what I want to do is have my parser cough up a mini-document for particular nodes and I don't see an easy way to do this, or at least not a…
Jim B.
  • 4,512
  • 3
  • 25
  • 53
3
votes
1 answer

scala.xml.PrettyPrinter to format shorter node when there is no text in it

I use scala.xml.PrettyPrinter to format my XML in Scala. The problem is with nodes without text content. Instead of this: I'd prefer to have this: How can I make PrettyPrinter to format it my way?
amorfis
  • 15,390
  • 15
  • 77
  • 125
3
votes
1 answer

Scala XML pull parser and location

I have been asked to write a utility to search a large number of XML files for elements with a missing attribute. The department responsible cannot just make the attribute mandatory in the DTD because it will break hundreds of files. They want to…
Ralph
  • 31,584
  • 38
  • 145
  • 282
3
votes
1 answer

Scala how to retrieve xml tag with optional attribute

I am trying to get scala xml node tag with attribute. I would like to get just the tag name with attribute and not the child elements. I have this input:
nancy
  • 55
  • 4
3
votes
3 answers

Why I cannot filter on this condition on reading xml and filter

I have a sample code import org.apache.spark.sql.Row import scala.xml._ object reading_xml { def main(args: Array[String]): Unit = { //I have 42 Millions of records val records = List( …
tree em
  • 20,379
  • 30
  • 92
  • 130
3
votes
1 answer

Scala XML extract the element in comma separator

My Code scala.xml.XML.loadString("" + line(1)).child It will give me the list like this: List(KH0011201, -1, 380, 50000, ) I want to be like this KH0011201, -1, 380,…
tree em
  • 20,379
  • 30
  • 92
  • 130
3
votes
2 answers

How to create xml attributes dynamic via Map in scala

I have one Map which contains some attributes, and I'd like to create a xml element which has these attributes. e.g. config is scala Map, and I want to use it as following, but actually the following doesn't work. Could anyone help me ?…
zjffdu
  • 25,496
  • 45
  • 109
  • 159
3
votes
2 answers

How do I declare embedded css with Binding.scala

I tried to declare some embedded css with Binding.scala import com.thoughtworks.binding._, Binding._ import org.scalajs.dom._ @dom def css = dom.render(document.head, css) However, I…
Yang Bo
  • 3,586
  • 3
  • 22
  • 35
3
votes
2 answers

Add or append new element to XML file in Scala instead of replacing it

My scala code currently ends up replacing an entire section of my xml file with the new tag that I'm adding. I want it to only add the tag once as a child of ClientConfig but it replaces all the tags present in this section with itself. val data =…
Zee
  • 1,321
  • 2
  • 18
  • 41
1
2 3 4 5