Ruby 2.1.0 リファレンスマニュアル > ライブラリ一覧 > rexml/documentライブラリ > REXML::Attributeクラス > namespace

instance method REXML::Attribute#namespace

namespace(arg = nil) -> String | nil[permalink][rdoc]

属性の名前空間の URI を返します。

URI が定義されていない場合は nil を返します。

[PARAM] arg:
この値を指定すると、その属性の名前空間でなく、arg という名前空間の URI が返されます。通常は省略します。

require 'rexml/document'
e = REXML::Element.new("el")
e.add_attribute("xmlns:ns", "http://www.example.com/ns")
e.add_attribute("ns:r", "rval")
p e.attributes.get_attribute("r").prefix  # => "ns"
p e.attributes.get_attribute("r").namespace # => "http://www.example.com/ns"