scala - Adding an XML attribute conditionally -
i need way add xml attribute 'positon' xml element 'node' conditionally. i'm doing condition check first , creating node.
if (lvl == 2) node = <node color={ color } created={ epochtimemillis } id={ idgen } position={ position } link={ link } modified={ epochtimemillis } style="bubble" text={ f.getname() }> <edge color={ color } style={ style } width={ width }/> </node> else node = <node color={ color } created={ epochtimemillis } id={ idgen } link={ link } modified={ epochtimemillis } style="bubble" text={ f.getname() }> <edge color={ color } style={ style } width={ width }/> </node> }
using "null" not practice, in case you:
scala> <root ta={ if (true) "true" else null } fa={ if (false) "false" else null } /> res0: scala.xml.elem = <root ta="true" ></root>
Comments
Post a Comment