X-Git-Url: http://nitlanguage.org diff --git a/lib/dom/dom.nit b/lib/dom/dom.nit index 9234057..786bdcc 100644 --- a/lib/dom/dom.nit +++ b/lib/dom/dom.nit @@ -12,3 +12,58 @@ module dom import parser + +redef class XMLEntity + + # The `XMLTag` children with the `tag_name` + # + # ~~~ + # var code = """ + # + # + # + # This is a white tiger! + # + # """ + # + # var xml = code.to_xml + # assert xml["animal"].length == 1 + # assert xml["animal"].first["cat"].length == 2 + # ~~~ + fun [](tag_name: String): Array[XMLEntity] + do + var res = new Array[XMLEntity] + for child in children do + if child isa XMLTag and child.tag_name == tag_name then + res.add child + end + end + return res + end +end + +redef class XMLStartTag + + # Content of this XML tag held within a `PCDATA` or `CDATA` + # + # ~~~ + # var code = """ + # + # + # + # This is a white tiger! + # + # """ + # + # var xml = code.to_xml + # assert xml["animal"].first["tiger"].first.as(XMLStartTag).data == "This is a white tiger!" + # ~~~ + fun data: String + do + for child in children do + if child isa PCDATA then return child.content + if child isa CDATA then return child.content + end + abort + end +end