开发者

Removing nodes from XML

开发者 https://www.devze.com 2023-01-19 01:21 出处:网络
I want to produce an XML document from another, filtering subnodes that match a s开发者_开发技巧pecified criterion. How should I do that?You can use RuleTransformer from scala.xml.transform.

I want to produce an XML document from another, filtering subnodes that match a s开发者_开发技巧pecified criterion. How should I do that?


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号