File: xmlcheck.rb

package info (click to toggle)
libxml-parser-ruby 0.6.8-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 932 kB
  • ctags: 1,525
  • sloc: ruby: 11,080; ansic: 1,958; xml: 467; makefile: 6
file content (40 lines) | stat: -rwxr-xr-x 783 bytes parent folder | download | duplicates (3)
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