diff --git a/cli/src/main/resources/scalaxb.scala.template b/cli/src/main/resources/scalaxb.scala.template
index 607093b11..e8e96db60 100644
--- a/cli/src/main/resources/scalaxb.scala.template
+++ b/cli/src/main/resources/scalaxb.scala.template
@@ -62,6 +62,7 @@ trait CanReadXML[A] {
}
trait CanWriteXML[A] {
+ def defaultElementLabel: Option[String] = None
def writes(obj: A, namespace: Option[String], elementLabel: Option[String],
scope: NamespaceBinding, typeAttribute: Boolean): NodeSeq
}
@@ -733,7 +734,7 @@ trait CanWriteChildNodes[A] extends CanWriteXML[A] {
def writes(obj: A, namespace: Option[String], elementLabel: Option[String],
scope: scala.xml.NamespaceBinding, typeAttribute: Boolean): scala.xml.NodeSeq = {
val elem = scala.xml.Elem(Helper.getPrefix(namespace, scope).orNull,
- elementLabel getOrElse { sys.error("missing element label.") },
+ elementLabel orElse defaultElementLabel getOrElse { sys.error("missing element label.") },
writesAttribute(obj, scope),
scope, true,
writesChildNodes(obj, scope): _*)
diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala b/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala
index 9b50572d9..add9f93f2 100644
--- a/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala
+++ b/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala
@@ -168,7 +168,8 @@ class GenSource(val schema: SchemaDecl,
}}
case _ => Left("reads failed: seq must be scala.xml.Node")
}}
-
+
+ override val defaultElementLabel: Option[String] = { quote(decl.family.headOption) }
def writes(__obj: {fqn}, __namespace: Option[String], __elementLabel: Option[String],
__scope: scala.xml.NamespaceBinding, __typeAttribute: Boolean): scala.xml.NodeSeq = __obj match {{
{ val cases = for (sub <- context.baseToSubs(decl))
@@ -388,6 +389,7 @@ class GenSource(val schema: SchemaDecl,
def defaultFormats = if (simpleFromXml)
else