Skip to content

Commit

Permalink
dom: intro XMLTag::attributes_to_map mapping XMLStringAttr to the…
Browse files Browse the repository at this point in the history
…ir value

Signed-off-by: Alexis Laferrière <[email protected]>
  • Loading branch information
xymus committed May 23, 2017
1 parent 69cb351 commit 6528367
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/dom/dom.nit
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,27 @@ redef class XMLStartTag
abort
end
end

redef class XMLAttrTag

# Attributes as a map (ignoring malformed attributes)
#
# ~~~
# var xml = """
# <student first="Snow" last="Man"/>
# """.to_xml
#
# var attributes = xml["student"].first.as(XMLAttrTag).attributes_to_map
# assert attributes.join(", ", ":") == "first:Snow, last:Man"
# ~~~
fun attributes_to_map: Map[String, String]
do
var m = new Map[String, String]
for a in attributes do
if a isa XMLStringAttr then
m[a.name] = a.value
end
end
return m
end
end

0 comments on commit 6528367

Please sign in to comment.