Method: ROXML::ClassMethods::Declarations#xml_namespaces

Defined in:
lib/roxml.rb

#xml_namespaces(namespaces) ⇒ Object

Sets up a mapping of namespace prefixes to hrefs, to be used by this class. These namespace prefixes are independent of what appears in the xml, only the namespace hrefs themselves need to match

Example: class Tires include ROXML

xml_namespaces \
 :bobsbike => 'http://bobsbikes.example.com',
 :alicesauto => 'http://alicesautosupply.example.com/'

xml_reader :bike_tires, :as => [], :from => '@name', :in => 'bobsbike:tire'
xml_reader :car_tires, :as => [], :from => '@name', :in => 'alicesauto:tire'

end

xml = %{

} >> Tires.from_xml(xml).bike_tires => ['skinny street']


111
112
113
114
115
116
# File 'lib/roxml.rb', line 111

def xml_namespaces(namespaces)
  @roxml_namespaces = namespaces.inject({}) do |all, (prefix, href)|
    all[prefix.to_s] = href.to_s
    all
  end
end