Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > rexml/documentライブラリ > REXML::Attributesクラス > get_attribute
get_attribute(name) -> Attribute | nil
[permalink][rdoc]name という名前の属性を取得します。
name という名前を持つ属性がない場合は nil を返します。
[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='<'/>
</root>
EOS
a = doc.get_elements("/root/a").first
a.attributes.get_attribute("att") # => att='<'
a.attributes.get_attribute("foo:att") # => foo:att='1'