Working With XML

Knoldus Blogs

Hi All,

In this blog, I will share some basic information that will help you more to work with an XML file.The first thing to know about XML in Scala is that Scala can process XML literals. so you don’t need to have any specific dependencies for working with XML. you can directly put the whole XML to Scala REPL and  Scala will automatically interpret them as XML elements.

so let’s do some basics example to get an understanding of how to play with XML
scala> val foo = <foo><bar type="greet">hi</bar><bar type="count">1</bar><bar type="color">yellow</bar></foo>
foo: scala.xml.Elem = <foo><bar type="greet">hi</bar><bar type="count">1</bar><bar type="color">yellow</bar></foo>

so if you want to retrieve the values of each tag then you can use –

scala> foo.text
res0: String = hi1yellow

so here you can see I just apply  .text on foo and it gave me the text values of each XML tag without any space.

if you want to retrieve the value of…

View original post 343 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s