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
3
votes
1 answer

In Scala, how can I put an incrementing ID in XML element using transformer / Rewrite rule

I want to read in a XML file and put an incrementing id in specific elements. Here is some test code I wrote to figure out how to do that: import scala.xml._ import scala.xml.transform._ val testXML =
2
votes
2 answers

How to convert list of scala Xml elements to single scala Elements?

So I have val list:List[Any]; def toElement(a:Any):scala.xml.Elem; And I want to write somthing like val result = {list.map(toElement).toElem}
yura
  • 14,489
  • 21
  • 77
  • 126
2
votes
1 answer

How do I create ordered xml elements in scala?

This seems wrong to me - why is the order of the elements changed from the order they are built? scala> var list = collection.immutable.TreeSet(1, 3, 2, 5, 0) list: scala.collection.immutable.TreeSet[Int] = TreeSet(0, 1, 2, 3, 5) scala> var xml =…
Dave Clay
  • 21
  • 1
2
votes
2 answers

Scala XML pattern matching, top level element

Consider the following XML node:

What is the correct way to pattern match the top level element in Scala? I would expect the following to work but it does not: def visit(node:Node):String = { …

kostas
  • 1,959
  • 1
  • 24
  • 43
2
votes
1 answer

append xml node if it not present in the list

I have block of code: object XmlExample { def main(args: Array[String]): Unit = { val someXml = Wilkie Collins
tree em
  • 20,379
  • 30
  • 92
  • 130
2
votes
1 answer

Scala XML literal - Boolean vs String

I ran into this behavior which surprised me. Essentially, if I create "the same" XML Elem from two different XML literals, they fail to equal one another. The unique thing here is that I am using a Boolean in one and a String in the other. scala>…
dwikle
  • 6,820
  • 1
  • 28
  • 38
2
votes
3 answers

Parsing with scala-xml API with multiple attributes

I have XML that I'm trying to use Scala XML API. I have XPath queries to retrieve the data from the XML tags. I want to retrieve tag value from but using the two attributes _id and type. I want to write a condition with && so that…
Pardeep Sharma
  • 572
  • 5
  • 20
2
votes
1 answer

Filtering XML elements with null attributes

I'm trying to extract attributes from a regular XML structure; it seems natural to first exclude the elements for which a particular attribute is missing. I don't know why the following doesn't work (see answer for why I ever got the idea to test…
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
2
votes
1 answer

Scala - Modify value of arbitrary XML element

I want to choose arbitrary element in xml at runtime and update its value. For example, given xml like 123 456 I want to arbitrary pick either or at runtime (not hardcoded) and update its value.…
Hiren
  • 708
  • 1
  • 7
  • 14
2
votes
1 answer

Scala: akka http unmarshal xml strings to case classes

I have a simple XML response from third-party API. Let's say it looks like Having a case classes case class Items(children: List[Item]) case class…
Igor Loskutov
  • 2,157
  • 2
  • 20
  • 33
2
votes
1 answer

Using Scala pattern matching to extract XML elements with a certain name, regardless of content

Given the following XML elements -- val nodes = List( , , , qux, , waldo, ) -- how do I construct a pattern that matches…
David Moles
  • 48,006
  • 27
  • 136
  • 235
2
votes
2 answers

Remove prefixed attribute in scala (scala-xml)

I am trying to remove an attribute with prefix in Scala using a RuleTransformer. While the following works with unprefixed attributes: val xml = content val rw1 = new RewriteRule { override def transform(n:…
shscoder
  • 92
  • 1
  • 9
2
votes
2 answers

How to handle nil in scala XML parsing?

I have a XML document representing my model that I need to parse and save in db. In some fields it may have NULL values indicated by xsi:nil. Like so For parsing I use scala.xml DSL. The problem is I can't find any way of…
Lubiluk
  • 704
  • 5
  • 12
1
vote
0 answers

Change dependency version number in pom.xml using scala-xml

I want to use scala-xml to change the version number of one dependency in a bunch of pom.xml files. I know this is normally not the best way to approach such a task but in my use case I think it is. Here is an example pom.xml
avs
  • 617
  • 5
  • 13
1
vote
1 answer

NullPointerException on XML.loadFile()

I am trying to load an xml file using scala-xml_2.12-1.0.6.jar but it gives me NullPointerEexception while loading Following is my line of code to load xml import scala.xml.XML val xml = XML.loadFile("sample.xml") I have decompiled this jar and is…
M.Ahsen Taqi
  • 965
  • 11
  • 35