I've discovered that Scala XML literals are sensitive to whitespace, which is kinda strange, isn't it? since XML parsers don't normally give a damn about spaces between the tags.
This is a bummer because I'd like to set out my XML neatly in my code:
<sample>
<hello />
</sample>
but Scala considers this to be a different value to
<sample><hello /></sample>
Proof is in the pudding:
scala> val xml1 = <sample><hello /></sample>
xml1: scala.xml.Elem = <sample><hello></hello></sample>
scala> val xml2 = <sample>
| <hello />
| </sample>
xml2: scala.xml.Elem =
<sample>
<hello></hello>
</sample>
scala> xml1 == <sample><hello /></sample>
res0: Boolean = true
scala> xml1 == xml2
res1: Boolean = false
... What gives?
XML Naming Rules Element names cannot start with the letters xml (or XML, or Xml, etc) Element names can contain letters, digits, hyphens, underscores, and periods. Element names cannot contain spaces.
You can add space in HTML to any lines of text. You can use the HTML entity to create blank spaces in both paragraph text and text in tables, for example. Since there is no blank space keyboard character in HTML, you must type the entity for each space to add.
If you liked it you should have put a trim on it:
scala> val xml1 = <sample><hello /></sample>
xml1: scala.xml.Elem = <sample><hello></hello></sample>
scala> val xml2 = <sample>
| <hello />
| </sample>
xml2: scala.xml.Elem =
<sample>
<hello></hello>
</sample>
scala> xml1 == xml2
res14: Boolean = false
scala> xml.Utility.trim(xml1) == xml.Utility.trim(xml2)
res15: Boolean = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With