Sha256: baf34de86cf12413c6225d7c13eb18fd2dba7618a136a26cbf48cc76c2c4abd4
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
#! /usr/local/bin/ruby require 'xmlextparser' class TestParser < XML::ExtParser def externalParsedEntityDecl(entname, base, sysid, pubid) p ["externalParsedEntityDecl", entname, base, sysid, pubid] end def internalParsedEntityDecl(entname, text) p ["internalParsedEntityDecl", entname, text] end def escapeAttrVal(str) ret = "" str.scan(/./um) do |c| code = c.unpack("U")[0] if code == 9 || code == 10 || code == 13 ret << sprintf("&#x%X;", code) elsif c == "&" ret << "&" elsif c == "\"" ret << """ elsif c == "<" ret << "<" else ret << c end end ret end def escapeText(str) ret = "" str.scan(/./um) do |c| code = c.unpack("U")[0] if code == 13 ret << sprintf("&#x%X;", code) elsif c == "&" ret << "&" elsif c == "<" ret << "<" elsif c == ">" ret << ">" else ret << c end end ret end def startElement(name, attrs) print "<" + name attrs.each do |n, v| print " " + n + "='" + escapeAttrVal(v) + "'" end print ">" end def endElement(name) print "</" + name + ">" end def character(text) print escapeText(text) end end p = TestParser.new pos = ARGV[0].rindex("/") if pos p.setBase(ARGV[0][0, pos + 1]) else p.setBase("") end begin p.parse($<.read) rescue XML::Parser::Error p([$!, p.line]) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mame-xmlparser-0.6.81.1 | samples/expat-1.2/exttest.rb |