Search code examples
scalascala-xml

Scala XML Html like split at </br>?


Hello currently given the following string:

<strong>Headline</strong>Line 1<br/>Line 2<br/>Line 3<br/>Line 4<br/>Line 5<br/>

How could I extract the text so that I get:

Headline
Line 1
Line 2
...

Currently the biggest problem for me is that Scala XML .text will remove the node's and won't make a \n at , however that is odd. Is there a way to get a \n for each ?


Solution

  • Assume you expect smth like following:

    scala> val x = <x><strong>Headline</strong>Line 1<br/>Line 2<br/>Line 3<br/>Line 4<br/>Line 5<br/></x>
    scala> println(x.child.map { v => v.text}.mkString("\n"))
    Headline
    Line 1
    
    Line 2
    
    Line 3
    
    Line 4
    
    Line 5