substituting xml values programmatically with scala

后端 未结 3 1664
有刺的猬
有刺的猬 2021-01-03 04:42

I\'m writing a tool to update some xml files (pom.xml in this case) with scala because the effort it would take in java is significantly higher than (in theory) it is with s

3条回答
  •  借酒劲吻你
    2021-01-03 05:40

    Text is represented as a Node inside of the Elements Node. So a bit of functional recursion will let you do a deep copy & filter:

    def deepCopy(node:Node) : Node = node match {
      case e : Elem => e.copy(child = this.child.toSeq.map(deepCopy))
      case t : Text => new Text(t.text.split("-").head)
      case x => x
    }
    

    disclaimer: this code was not tested for errors

提交回复
热议问题