Scala XML varargs attributes -


ran across ancient thread on applying varargs xml node, no definitive answer particular problem came of (accepted answer answers but issue).

have pretty gruesome hack in place avoid resorting xml.loadstring("...") generating xhtml form fields.

def nodecopy(e: elem, args: (symbol,any)*): elem = {    val = args.map{case(s,v)=> attribute(none,s.name,text(v.tostring),null) }   a.size match{     case 0 => e     case 1 => e % a(0)     case 2 => e % a(0) % a(1)      case 3 => e % a(0) % a(1) % a(2)     case 4 => e % a(0) % a(1) % a(2) % a(3)     case 5 => e % a(0) % a(1) % a(2) % a(3) % a(4)     case 6 => e % a(0) % a(1) % a(2) % a(3) % a(4) % a(5)     case _ => e % a(0) % a(1) % a(2) % a(3) % a(4) % a(5) % a(6)   } }  // usage (where args be: ('id, "foo"), ('class, "bar"), ...) nodecopy(<input name={k} value={v} />, args:_*) 

is there better approach generating dynamic xml elems scala 2.10??

here's literal translation fold:

def nodecopy(e: elem, args: (symbol, any)*): elem = args.foldleft(e) {   case (currentelem, (s, v)) =>     currentelem % attribute(none, s.name, text(v.tostring), null) } 

this works same implementation, arbitrarily many attributes.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -