Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xml attribute rendering oddness

Tags:

scala

Using 2.9.0.1

<b time={None}>Hello</b>

=>

<b >Hello</b>

i.e. there is a space after the b in the starting tag. This makes no sense from an XML perspective.

Is this "feature" supposed to happen?

Thanks.

like image 782
Dino Fancellu Avatar asked Aug 15 '26 20:08

Dino Fancellu


1 Answers

It happens because of toString implementation of scala.xml.Elem, to be more specific in object scala.xml.MetaInf method buildString which looks like following:

 def buildString(sb: StringBuilder): StringBuilder = {
  sb.append(' ')
  toString1(sb)
  next.buildString(sb)
 }

So it's firstly adds a white space to string representation of element, and only after that appends next attribute, so if an attribute is present as class member but doesn't have any string representation you'll end up with one extra space before closing bracket

like image 100
Nikolay Ivanov Avatar answered Aug 18 '26 08:08

Nikolay Ivanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!