All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.kondaurovdev.xml.NodeIterator.scala Maven / Gradle / Ivy

package com.github.kondaurovdev.xml

import com.github.kondaurovdev.xml.XmlParser.ParseOptions

import scala.xml.Elem

object NodeIterator {

  def apply(raw: Elem, options: ParseOptions): NodeIterator = new NodeIterator(raw, options)

}

class NodeIterator(raw: Elem, options: XmlParser.ParseOptions) extends Iterator[Map[String, String]] {

  val nodes = raw \\ options.tagName

  val total = nodes.length

  val limit: Int = if (options.max > 0) {
    if (options.max > total) total else options.max
  } else total

  var current = 0

  def hasNext: Boolean = total > 0 && current < limit

  def next(): Map[String, String] = {
    val node = nodes(current)
    current += 1
    XmlNode(node).getFlatObj(options.fields, options.params)
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy