How to add attribute to Nokogiri node?

前端 未结 1 1594
情书的邮戳
情书的邮戳 2021-02-12 09:47

I\'m trying to add an attribute to an existing Nokogiri node. What I\'ve done is this:

node.attributes[\'foobar\'] = Nokogiri::XML::Attr.new(\'foo\', \'bar\')
         


        
1条回答
  •  感动是毒
    2021-02-12 10:05

    I believe you should just need to use the []= method, i.e.

    node['foo'] = 'bar'
    

    You could also use node.set_attribute('foo', 'bar').

    0 讨论(0)
提交回复
热议问题