You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- even though the two documents are formally equivalent. This makes it hard to write mapping classes when you don't know whether the elements are going to be at the root or embedded in another XML document, or what namespace they'll use in that other XML document.
I managed to come up with the awful hack below, but
I'm pretty new to Ruby and even newer to Ruby metaprogramming, so it's probably even more awful than it needs to be,
It only supports a global namespace on the element and all its attributes, and
because the prefix-to-URI information is only available at parsing time, it resets the (class-level) @namespaces attribute with every call to parse(), which is less than ideal and could cause various kinds of weirdness.
classAddress < NamespacedElement# note we no longer include HappyMapper, that's done by the superclassdefself.namespace_uriURI('http://www.unicornland.com/prefix')endhas_many:street,String,:tag=>'street'element:postcode,String,:tag=>'postcode'element:housenumber,String,:tag=>'housenumber'element:city,String,:tag=>'city'element:country,Country,:tag=>'country'end
It would be nice if there was a straightforward way to just set a namespace_uri and let the prefix be resolved at parse time.
The text was updated successfully, but these errors were encountered:
It doesn't seem to be possible to write one HappyMapper class that can parse both this document, with a global namespace --
-- and this document, with qualified names --
-- even though the two documents are formally equivalent. This makes it hard to write mapping classes when you don't know whether the elements are going to be at the root or embedded in another XML document, or what namespace they'll use in that other XML document.
I managed to come up with the awful hack below, but
@namespaces
attribute with every call toparse()
, which is less than ideal and could cause various kinds of weirdness.Example
It would be nice if there was a straightforward way to just set a
namespace_uri
and let the prefix be resolved at parse time.The text was updated successfully, but these errors were encountered: