File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -21,19 +21,30 @@ struct XML::Node
21
21
end
22
22
23
23
# Gets the attribute content for the *attribute* given by name.
24
- #
25
24
# Raises `KeyError` if attribute is not found.
26
25
def [] (attribute : String ) : String
27
26
attributes[attribute].content || raise(KeyError .new(" Missing attribute: #{ attribute } " ))
28
27
end
29
28
30
29
# Gets the attribute content for the *attribute* given by name.
31
- #
32
30
# Returns `nil` if attribute is not found.
33
31
def []? (attribute : String ) : String ?
34
32
attributes[attribute]?.try & .content
35
33
end
36
34
35
+ # Sets *attribute* of this node to *value*.
36
+ # Raises `XML::Error` if this node does not support attributes.
37
+ def []= (name : String , value : String )
38
+ raise XML ::Error .new(" Can't set attribute of #{ type } " , 0 ) unless element?
39
+ attributes[name] = value
40
+ end
41
+
42
+ # Deletes attribute given by *name*.
43
+ # Returns attributes value, or `nil` if attribute not found.
44
+ def delete (name : String )
45
+ attributes.delete(name)
46
+ end
47
+
37
48
# Compares with *other*.
38
49
def == (other : Node )
39
50
@node == other.@node
You can’t perform that action at this time.
0 commit comments