dam5s/happymapper — pull request #48 by Confusion (2014-05-14 11:29:11+00:00)
Title: Prioritize explicit namespace on element declaration above namespace on element type when generating XML

When an element declaration specifies a specific namespace, like in
````
class CoffeeMachine
element 'beverage', Beverage, namespace: 'beverages'
end
````
then that namespace should be used instead of the namespace declared by the
element type itself, which could e.g. be
````
class Beverage
namespace 'coffee'
attribute 'name', String
end
````

It used to be the case that a nested 'beverage' element would use the 'coffee'
namespaces. With this patch it uses the 'beverages' namespace.

This is necessary to produce the correct XML for cases where e.g. one XSD
specifies a type and another XSD uses that type, which is common in various
standard XSD's, as in the example below.

There is one 'victim': attribute namespacing. To namespace an attribute, you
now always explicitly need to specify the namespace. As attribute namespacing
is a rarely used feature of XML, I think that is a sacrifice we should be willing
to make.

Example
-------
We are dealing with a Subscribe element from the ws-base-notification XSD,
which has a ConsumerReference element which is of type EndpointReferenceType from
the ws-addressing XSD. The classes reflecting the XSD's look like:
````
class WsBaseNotification::Subscribe
register_namespace 'add', 'http://www.w3.org/2005/08/addressing'
register_namespace 'b', 'http://docs.oasis-open.org/wsn/b-2'

namespace 'b'
has_one :ConsumerReference, WsAddressing::EndpointReferenceType, namespace: 'b'
...
end

class WsAddressing::EndPointReferenceType
namespace 'add'
...
end
````
(note that 'b' and 'add' are the preferred prefixes for
'http://docs.oasis-open.org/wsn/b-2' and 'http://www.w3.org/2005/08/addressing')

The XML that used to be produced would be
````

...
````
Now it is:
````

...
````