Monday, 4 January 2016

XML : Parsing XML as NodeSeq, how to read the root element name?

When I read an XML file/string as a NodeSeq, how to get the name of the root element?

Seems kinda basic, but I don't see an immediately obvious way to do it, looking at NodeSeq API.

Minimal example:

Given arbitrary XML:

  <HelloWorld>      <Foo>Bar</Foo>  </HelloWorld>    

And code that loads it as NodeSeq:

  val xml: NodeSeq = XML.loadString(xmlString)    

What is the simplest way to get the root element name, in this case "HelloWorld"?

No comments:

Post a Comment