Home > front end >  Scala XML parse multiple fields
Scala XML parse multiple fields

Time:10-24

I have an XML document structured like:

<document>
  <Imposed_TimeSeries>
  ...
  </Imposed_TimeSeries>

  <Confirmed_TimeSeries>
  ...
  </Confirmed_TimeSeries>
</document>

I would like to get a NodeSeq of all TimeSeries elements with a filter like: (document \ "*_TimeSeries"). Is there any (easy) way to do this?

CodePudding user response:

You can use

    val result: NodeSeq = (xml \ "_").filter(_.label.contains("TimeSeries"))

Look at the source of \ :

this \ "_" to get a list of all child elements (wildcard);

But you need \\ to access your different TimeSeries

println(result \\ "Confirmed_TimeSeries")
println(result \\ "Imposed_TimeSeries")
  • Related