1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
18 # The `XMLTag` children with the `tag_name`
22 # <?xml version="1.0" encoding="us-ascii"?>
25 # <tiger>This is a white tiger!</tiger>
29 # var xml = code.to_xml
30 # assert xml["animal"].length == 1
31 # assert xml["animal"].first["cat"].length == 2
33 fun [](tag_name
: String): Array[XMLTag]
35 var res
= new Array[XMLTag]
36 for child
in children
do
37 if child
isa XMLTag and child
.tag_name
== tag_name
then
45 redef class XMLStartTag
47 # Content of this XML tag held within a `PCDATA` or `CDATA`
51 # <?xml version="1.0" encoding="us-ascii"?>
54 # <tiger>This is a white tiger!</tiger>
58 # var xml = code.to_xml
59 # assert xml["animal"].first["tiger"].first.as(XMLStartTag).data == "This is a white tiger!"
63 for child
in children
do
64 if child
isa PCDATA then return child
.content
65 if child
isa CDATA then return child
.content
71 redef class XMLAttrTag
73 # Attributes as a map (ignoring malformed attributes)
77 # <student first="Snow" last="Man"/>
80 # var attributes = xml["student"].first.as(XMLAttrTag).attributes_to_map
81 # assert attributes.join(", ", ":") == "first:Snow, last:Man"
83 fun attributes_to_map
: Map[String, String]
85 var m
= new Map[String, String]
86 for a
in attributes
do
87 if a
isa XMLStringAttr then