1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#! /usr/local/bin/ruby
## XML checker
## 1999 by yoshidam
##
## Sep 14, 1999 yoshidam: unknownEncoding ٥б
## Jul 26, 1998 yoshidam: Shift_JIS, ISO-2022-JP б
## 顼ɽ SP ѹ
require 'xml/parser'
require 'nkf'
class XMLRetry<Exception; end
xml = $<.read
parser = XML::Parser.new
def parser.unknownEncoding(e)
raise XMLRetry, e
end
begin
parser.parse(xml)
print "well-formed\n"
exit 0
rescue XMLRetry
newencoding = nil
e = $!.to_s
if e =~ /^iso-2022-jp$/i
xml = NKF.nkf("-Je", xml)
newencoding = "EUC-JP"
end
parser = XML::Parser.new(newencoding)
retry
rescue XML::Parser::Error
line = parser.line
column = parser.column
print "#{$0}:#{$<.filename}:#{line}:#{column}:E: #{$!}\n"
exit 1
end
|