Suppose I am printing out an XML element like this: def toXML: xml.Elem = { <waypt name={name}> ... </waypt> } The "name" attribute is a String and is optional (some waypoints have names and some don't). I want to show it only if it is nonempty. In other words, I don't want to see name="" I just want the name attribute completely omitted if the name is an empty String. How can I do that in the toXML method above? Thanks. You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
I don't know if there's a better solution, but Elem is a case class so you can add the attribute on afterwards using the copy method. On Fri, Mar 24, 2017 at 2:01 AM Russ P. <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Russ P.
Hi,
-- If you make "name" an Option[scala.xml.Text], I think the XML will be generated as you desire. Dan On Friday, March 24, 2017 at 2:01:33 AM UTC-4, Russ P. wrote:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Nice. Thanks! On Tue, Mar 28, 2017 at 8:49 PM, Daniel Manchester <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |