substituting xml values programmatically with scala

后端 未结 3 1685
有刺的猬
有刺的猬 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:49

    Using Scalate's Scuery CSS3 transforms and scala.xml.Elem#copy:

    val xml =
      
        1.0-SNAPSHOT
        2.0
      
    
    new Transformer {
      $("dependency > version") { node =>
        node.asInstanceOf[Elem].copy(child = Text(node.text.stripSuffix("-SNAPSHOT")))
      }
    }.apply(xml)
    

    yields

    NodeSeq(1.02.0)
    

提交回复
热议问题