Skip to content

Commit 8e71456

Browse files
committed
get/set index for attributesa
1 parent 177afb0 commit 8e71456

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/XML.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ function Base.setindex!(o::Node, val, key::AbstractString)
156156
end
157157
o.attributes[key] = string(val)
158158
end
159+
Base.getindex(o::Node, val::AbstractString) = isnothing(o.attributes) ? nothing : get(o.attributes, val, nothing)
159160

160161
Base.show(io::IO, o::Node) = _show_node(io, o)
161162

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,9 @@ end
163163
@test nodetype(doc[end][2]) == XML.Text
164164
@test value(doc[end][1]) == "cdata"
165165
@test value(doc[end][2]) == "text"
166+
167+
#set/get index for attributes
168+
o = doc[end]
169+
o["id"] = 1
170+
@test o["id"] == "1"
166171
end

0 commit comments

Comments
 (0)