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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#! /usr/local/bin/ruby
## XML checker
## 1998 by yoshidam
##
## Jul 26, 1998 yoshidam: Shift_JIS, ISO-2022-JP б
## 顼ɽ SP ѹ
require 'xmlparser'
require 'kconv'
include Kconv
begin
require 'uconv'
include Uconv
uconv = true
rescue
uconv = false
end
## empty file
if ((xml = $<.gets).nil?); exit 1; end
## rewrite encoding in XML decl.
if uconv
if xml =~ /^<\?xml\sversion=.+\sencoding=.EUC-JP./i
xml.sub!(/EUC-JP/i, "UTF-8")
encoding = 'EUC-JP'
elsif xml =~ /^<\?xml\sversion=.+\sencoding=.Shift_JIS./i
xml.sub!(/Shift_JIS/i, "UTF-8")
encoding = "Shift_JIS"
elsif xml =~ /^<\?xml\sversion=.+\sencoding=.ISO-2022-JP./i
xml.sub!(/ISO-2022-JP/i, "UTF-8")
encoding = "ISO-2022-JP"
end
end
## read body
xml += String($<.read)
## convert body encoding
if uconv
if encoding == "EUC-JP"
xml = euctou8(xml)
elsif encoding == "Shift_JIS"
xml = euctou8(kconv(xml, EUC, SJIS))
elsif encoding == "ISO-2022-JP"
xml = euctou8(kconv(xml, EUC, JIS))
end
end
parser = XMLParser.new
begin
parser.parse(xml)
print "well-formed\n"
exit 0
rescue XMLParserError
line = parser.line
column = parser.column
print "#{$0}:#{$<.filename}:#{line}:#{column}:E: #{$!}\n"
exit 1
end
|