eed3si9n/scalaxb — Issue #135: Extending base from different namespace puts elements from that namespace in the wrong namespace
Author: psnively
Created: 2012-01-31 15:32:12+00:00
State: open

Given one xsd, say common.xsd:

--------------------------------common.xsd--------------------------------

...

none

Optional link to an entity or operation associated
with this object.

always

Contains the URI to the entity.

always

Contains the type of the entity.

...
--------------------------------/common.xsd--------------------------------

And another, vmwextensions.xsd:

--------------------------------vmwextensions.xsd--------------------------------

...

1.0

Represents a list of available network pools.

none

Reference to a network pool.

...
--------------------------------/vmwextensions.xsd--------------------------------

where VMWNetworkPoolReferencesType extends ResourceType from common.xsd, which is in the vcloud namespace, we find, in xmlprotocol.scala:

--------------------------------xmlprotocol.scala--------------------------------
...
trait DefaultVcloudVMWNetworkPoolReferencesTypeFormat extends scalaxb.ElemNameParser[com.vmware.api.vcloud.VMWNetworkPoolReferencesType] {
val targetNamespace: Option[String] = Some("http://www.vmware.com/vcloud/extension/v1.5")

override def typeName: Option[String] = Some("VMWNetworkPoolReferencesType")

def parser(node: scala.xml.Node, stack: List[scalaxb.ElemName]): Parser[com.vmware.api.vcloud.VMWNetworkPoolReferencesType] =
rep(scalaxb.ElemName(Some("http://www.vmware.com/vcloud/extension/v1.5"), "VCloudExtension")) ~
rep(scalaxb.ElemName(Some("http://www.vmware.com/vcloud/extension/v1.5"), "Link")) ~
rep(scalaxb.ElemName(Some("http://www.vmware.com/vcloud/extension/v1.5"), "NetworkPoolReference")) ^^
{ case p1 ~ p2 ~ p3 =>
com.vmware.api.vcloud.VMWNetworkPoolReferencesType(p1.toSeq map { scalaxb.fromXML[com.vmware.api.vcloud.VCloudExtensionType](_, scalaxb.ElemName(node) :: stack) },
p2.toSeq map { scalaxb.fromXML[com.vmware.api.vcloud.LinkType](_, scalaxb.ElemName(node) :: stack) },
p3.toSeq map { scalaxb.fromXML[com.vmware.api.vcloud.ReferenceTypable](_, scalaxb.ElemName(node) :: stack) },
(node \ "@href").headOption map { scalaxb.fromXML[java.net.URI](_, scalaxb.ElemName(node) :: stack) },
(node \ "@type").headOption map { scalaxb.fromXML[String](_, scalaxb.ElemName(node) :: stack) },
scala.collection.immutable.ListMap((node match {
case elem: scala.xml.Elem =>
elem.attributes.toList flatMap {
case scala.xml.UnprefixedAttribute(key, value, _) if key == "href" => Nil
case scala.xml.UnprefixedAttribute(key, value, _) if key == "type" => Nil
case scala.xml.UnprefixedAttribute(key, value, _) =>
List(("@" + key, scalaxb.DataRecord(None, Some(key), value.text)))
case scala.xml.PrefixedAttribute(pre, key, value, _) =>
val ns = elem.scope.getURI(pre)
List(("@{" + ns + "}" + key, scalaxb.DataRecord(Option[String](ns), Some(key), value.text)))
case _ => Nil
}
case _ => Nil
}): _*)) }

override def writesAttribute(__obj: com.vmware.api.vcloud.VMWNetworkPoolReferencesType, __scope: scala.xml.NamespaceBinding): scala.xml.MetaData = {
var attr: scala.xml.MetaData = scala.xml.Null
__obj.href foreach { x => attr = scala.xml.Attribute(null, "href", x.toString, attr) }
__obj.typeValue foreach { x => attr = scala.xml.Attribute(null, "type", x.toString, attr) }
__obj.attributes.toList map {
case (key, x) => attr = scala.xml.Attribute((x.namespace map { __scope.getPrefix(_) }).orNull, x.key.orNull, x.value.toString, attr) }
attr
}

def writesChildNodes(__obj: com.vmware.api.vcloud.VMWNetworkPoolReferencesType, __scope: scala.xml.NamespaceBinding): Seq[scala.xml.Node] =
Seq.concat(__obj.VCloudExtension flatMap { scalaxb.toXML[com.vmware.api.vcloud.VCloudExtensionType](_, Some("http://www.vmware.com/vcloud/extension/v1.5"), Some("VCloudExtension"), __scope, false) },
__obj.Link flatMap { scalaxb.toXML[com.vmware.api.vcloud.LinkType](_, Some("http://www.vmware.com/vcloud/extension/v1.5"), Some("Link"), __scope, false) },
__obj.NetworkPoolReference flatMap { scalaxb.toXML[com.vmware.api.vcloud.ReferenceTypable](_, Some("http://www.vmware.com/vcloud/extension/v1.5"), Some("NetworkPoolReference"), __scope, false) })

}
...
--------------------------------/xmlprotocol.scala--------------------------------

This fails to parse the following actual XML from vCloud Director:

--------------------------------XML from vCD--------------------------------

--------------------------------/XML from vCD--------------------------------

The issue seems to be that scalaxb expects the "Link" element to be in the "http://www.vmware.com/vcloud/extension/v1.5" namespace instead of the "http://www.vmware.com/vcloud/v1.5" namespace. Removing the Link element from the XML results in a successful parse of the remainder.

The code that generates the XML appears to be of the opinion :-) that even though the NetworkPoolReference element is of type "vcloud:ReferenceType" it should be sent in the "http://www.vmware.com/vcloud/extension/v1.5" namespace, presumably because the element declaration is in that namespace. Hopefully that's correct, and all that needs to be resolved is the namespace of the inherited elements and attributes from the base.