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

instance method REXML::Attributes#get_attribute

get_attribute(name) -> Attribute | nil[permalink][rdoc]

name という名前の属性を取得します。

name という名前を持つ属性がない場合は nil を返します。

[PARAM] name:
属性名(文字列)

[SEE_ALSO] REXML::Attributes#[]


require 'rexml/document'

doc = REXML::Document.new(<<-EOS)
<root xmlns:foo="http://example.org/foo"
      xmlns:bar="http://example.org/bar">
  <a foo:att='1' bar:att='2' att='&lt;'/>
</root>
EOS
a = doc.get_elements("/root/a").first

a.attributes.get_attribute("att") # => att='&lt;'
a.attributes.get_attribute("foo:att") # => foo:att='1'