Removing nodes from XML

前端 未结 1 460
南旧
南旧 2021-02-01 18:07

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

相关标签:
1条回答
  • 2021-02-01 18:54

    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 讨论(0)
提交回复
热议问题