Scala - replace xml element with specific text -


so have xml

<a>blah</a> 

and want change

<a>somevalueidonotknowatcompiletime</a> 

currently, looking @ this question . however, changes value "2"

what want same thing, able define value (so can change @ runtime - reading values file!)

i tried passing value overridden methods, didn't work - compile errors everywhere (obviously)

how can change static xml dynamic values?

adding code

var splitstring = somestring.split("/t") //where somestring line file val action = splitstring(0) val ref = splitstring(1) xmlmap.get(action) match { //maps  "action" string xml     case some(entry) => {         val xmltosend = insertrefintoxml(ref,entry)          //for different xml, want put string "ref" in appropriate place     }     ... 

for example:

scala> val x = <foo>hi</foo> x: scala.xml.elem = <foo>hi</foo>  scala> x match { case <foo>{what}</foo> => <foo>{system.nanotime}</foo> } res1: scala.xml.elem = <foo>213370280150006</foo> 

update linked example:

import scala.xml._ import system.{ nanotime => }  object test extends app {   val inputxml : node =     <root>       <subnode> <version>1</version> </subnode>       <contents> <version>1</version> </contents>     </root>   def substitution =   // whatever   def updateversion(node: node): node = node match {     case <root>{ ch @ _* }</root> => <root>{ ch.map(updateversion )}</root>     case <subnode>{ ch @ _* }</subnode> => <subnode>{ ch.map(updateversion ) }</subnode>     case <version>{ contents }</version> => <version>{ substitution }</version>     case other @ _ => other   }   val res = updateversion(inputxml)   val pp = new prettyprinter(width = 2, step = 1)   console println (pp format res) } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -