# eine einfache XML Objektstruktur # ------------------------------ class XmlText def initialize(t) @text = t end def XmlText.from_s(t) # missing entity and char ref # substitution should be added here XmlText.new(t) end def to_s @text end end # ------------------------------ class XmlComment def initialize(c) @comment = c end def XmlComment.from_s(s) t = s.clone t[0..3] = "" t[-3..-1] = "" XmlComment.new(t) end def to_s "" end end # ------------------------------ class XmlEndTag def initialize(n) @name = n end def XmlEndTag.from_s(t) t = t.chop t[0..1] = "" XmlEndTag.new(t.strip) end def to_s "" end end # ------------------------------ class XmlBeginTag def initialize(s,al) @name = s @attrl = al end def XmlBeginTag.from_s(s) al = s.chop al[0..0] = "" n = al.split[0] al[0...n.length] = "" # missing entity and char ref # substitution should be added here XmlBeginTag.new(n, tokenizeAttrl(al)) end def to_s "<" + @name + ato_s + ">" end def ato_s res = "" @attrl.each_pair do |n,v| res << " " << n << '="' + v + '"' end res end end # ------------------------------ class XmlEmptyElem def XmlEmptyElem.from_s(t) t = t.chop.chop t[0..0] = "" n = t.split[0] [ XmlBeginTag.from_s("<" + t + ">"), XmlEndTag .from_s("") ] end end # ------------------------------ class XmlPi def initialize(n,c) @name = n @contents = c end def XmlPi.from_s(s) n = s.split[0] n[0..1] = "" c = s[(2 + n.length + 1)..(s.length - 2)] XmlPi.new(n,c) end def to_s "" end end # ------------------------------ class XmlDTD def initialize(d) @dtd = d end def XmlDTD.from_s(s) c = s[10 .. (s.length - 2)] XmlDTD.new(c) end def to_s "" end end # ------------------------------