tags:

views:

133

answers:

1

I want to produce an XML document from another, filtering subnodes that match a specified criterion. How should I do that?

+7  A: 

Hi Dave! You can use RuleTransformer from scala.xml.transform.

Suppose you have action attribute with "remove" value


val removeIt = new RewriteRule {
    override def transform(n: Node): NodeSeq = n match {
      case e: Elem if (e \ "@action").text == "remove" => NodeSeq.Empty
      case n => n
    }
  }

new RuleTransformer(removeIt).transform(yourXML)

walla