2016-10-26 7 views
0

Nokogiriノード要素から属性を削除しようとしています。ここでremove_attributeは、単に属性nokogiriを削除する代わりにnilノード要素を返す

は、最初のノードの要素である:

=> #(Element:0x3fed0eaf2ef0 { 
    name = "ins", 
    namespace = #(Namespace:0x3fed0ed24408 { prefix = "w", href = "http://schemas.openxmlformats.org/wordprocessingml/2006/main" }), 
    attributes = [ 
    #(Attr:0x3fed0eb1e528 { name = "id", namespace = #(Namespace:0x3fed0ed24408 { prefix = "w", href = "http://schemas.openxmlformats.org/wordprocessingml/2006/main" }), value = "0" }), 
    #(Attr:0x3fed0eb1e514 { name = "author", namespace = #(Namespace:0x3fed0ed24408 { prefix = "w", href = "http://schemas.openxmlformats.org/wordprocessingml/2006/main" }), value = "Mitchell Gould" }) 
    #(Attr:0x3fed0eb1e500 { name = "date", namespace = #(Namespace:0x3fed0ed24408 { prefix = "w", href = "http://schemas.openxmlformats.org/wordprocessingml/2006/main" }), value = "2016-10-15T14:43:00Z" })] 
    }) 

私が行うと:

first = all_ins_nodes.first.remove_attribute("name") 

first => nil 

私は唯一のノード全体の要素を削除しない属性を削除します。これどうやってするの?

答えて

1

右ここ

first = all_ins_nodes.first.remove_attribute("name") 

は理由が.remove_attributeが明らかにnilを返すということです

first = all_ins_node.first 
first.remove_attribute("name") 

複数行に分割する必要があります。ポインタが.firstコールの結果を参照するようにします。

+0

返信が遅れました。その有用で分かりやすい答えをありがとう。 – chell

関連する問題