[#30426] CGI でグラフを描くときにお勧めのライブラリは? — 堀川 久 <vzw00011@...>

こんにちは。

12 messages 2001/07/01

[#30453] syntax check without execution? — Tanaka Akira <akr@...17n.org>

最近、eRuby のまねごとをしていて、そのなかで Ruby のコードを生成してい

16 messages 2001/07/04
[#30455] Re: syntax check without execution? — matz@... (Yukihiro Matsumoto) 2001/07/04

まつもと ゆきひろです

[#30479] Object#dup — "Shin'ya Adzumi" <adzumi@...>

あづみです。

20 messages 2001/07/05

[#30512] open errno EALREADY triggerd — "Inoue" <inoue@...>

井上です。

16 messages 2001/07/08

[#30514] Ruby module frame work? — Takahiro Kambe <taca@...>

こんにちは。

16 messages 2001/07/09
[#30515] Re: Ruby module frame work? — matz@... (Yukihiro Matsumoto) 2001/07/09

まつもと ゆきひろです

[#30529] InterBase を使用したい — "YOUJI KUROKAWA" <CQE10242@...>

環境

22 messages 2001/07/09

[#30530] Question about script on the book "Ruby nyuumon" — NAWATE Masahiko <agul@...>

縄手@松江と言います。

17 messages 2001/07/09
[#30531] Re: Question about script on the book "Ruby nyuumon" — rubikitch <rubikitch@...> 2001/07/09

From: NAWATE Masahiko <agul@mag.shimane-u.ac.jp>

[#30533] Re: Question about script on the book "Ruby nyuumon" — NAWATE Masahiko <agul@...> 2001/07/09

縄手@松江です。

[#30734] UML クラス図と Ruby の記述についての対応 — Ken-ichi HASHIMOTO <ken@...>

橋本@福井県在住です。

13 messages 2001/07/28

[#30764] int/int => float? — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

50 messages 2001/07/31
[#30785] Re: int/int => float? — Konishi@... (Hiromasa KONISHI) 2001/07/31

 KONISHI Hiromasaです。

[#30767] Re: int/int => float? — keiju@... (石塚圭樹) 2001/07/31

けいじゅ@日本ラショナルソフトウェアです.

[#30768] Re: int/int => float? — matz@... (Yukihiro Matsumoto) 2001/07/31

まつもと ゆきひろです

[#30770] Re: int/int => float? — Take_tk <ggb03124@...> 2001/07/31

たけ(tk)です。

[#30771] Re: int/int => float? — matz@... (Yukihiro Matsumoto) 2001/07/31

まつもと ゆきひろです

[ruby-list:30655] XMLParser & DTD

From: skoba@... (KOBAYASHI Satoshi)
Date: 2001-07-18 06:32:50 UTC
List: ruby-list #30655
	はじめまして、小林@豊橋技術科学大学です。

    現在、XMLParserを用いてXML文書のパーズを試みております。しかし、ど
うもDTDを参照していないようで困っております。どのようにすればよろしい
のでしょうか? expat のコンパイル時には XML_DTDオプションを付けておりま
すので良いのかと思っていたのですが。よろしくお願いいたします。

    環境は以下の通りです。

    ruby        ver. 1.6.1
    expat       ver. 1.2
    XMLParser   ver. 0.6.1

    以下にプログラムを載せます。
#! /usr/local/bin/ruby

require 'parsearg'
require 'xmlparser'
require 'uconv'
require 'nkf'

class XMLRetry<Exception; end

ENTRY = 1;
READ  = 2;
POS   = 3;
INF   = 4;

def morphlist(file = nil, date = nil)

  ## file open
  if !file
    f = $stdin
  else
    begin
      f = open(file, "r")
    rescue
      $stderr.print "#{$0}: #{$!}\n";
      return
    end
  end


  ## read body
  xml = f.read
  f.close

  ## dummy default handler
  parser = XMLParser.new
  def parser.unknownEncoding(e)
    raise XMLRetry, e
  end
  def parser.default
  end

  ## start to parse

morph = Array.new;
element = ''

pdata = ''
i = 0;

  begin
    print XMLParser.expatVersion(),"\n";
    parser.parse(xml) do |type, name, data|
      case type
      when XMLParser::START_ELEM
        element = name
        case name
        when 'vocabulary'
        when 'head'
        when 'history'
        when 'version'
        when 'id'
        when 'date'
        when 'detail'
        when 'morph'
            i = i + 1
            morph[i] = Array.new
        when 'entry'
            morph[i][ENTRY] = ''
        when 'read'
            morph[i][READ] = ''
        when 'pos'
            morph[i][POS] = ''
        when 'inf'
            morph[i][INF] = ''
        end
      when XMLParser::END_ELEM
        case name
        when 'morph'
            print i,",";
            print morph[i][ENTRY],",";
            print morph[i][READ],",";
            print morph[i][POS],",";
            print morph[i][INF],"\n";
        end
      when XMLParser::CDATA
        next if data =~ /^\s*$/;
        data = Uconv.u8toeuc(data)
        case element
        when 'id'
        when 'date'
        when 'detail'
        when 'entry'
            data.gsub!(/^ +/,"")
            data.gsub!(/ +$/,"")
            morph[i][ENTRY] << data;
        when 'read'
            data.gsub!(/^ +/,"")
            data.gsub!(/ +$/,"")
            morph[i][READ] << data;
        when 'pos'
            data.gsub!(/^ +/,"")
            data.gsub!(/ +$/,"")
            morph[i][POS] << data;
        when 'inf'
            data.gsub!(/^ +/,"")
            data.gsub!(/ +$/,"")
            morph[i][INF] << data;
        end
      when XMLParser::PI
      else
      end
    end
  rescue XMLRetry
    newencoding = nil
    e = $!.to_s
    if e =~ /^iso-2022-jp$/i
      xml = NKF.nkf("-Je", xml)
      newencoding = "EUC-JP"
    end
    parser = XMLParser.new(newencoding)
    def parser.default; end
    retry
  rescue XMLParserError
    line = parser.line
    print "#{$0}: #{$!} (#{file}:#{line})\n"
  end
end

def usage
  $stderr.print "Usage: #{$0} [-d <date>] <file>\n"
  exit 1
end

parseArgs(0, nil, nil, "d:")
if (ARGV.length == 0)
  usage
end

morphlist(ARGV[0], $OPT_d)

__END__

In This Thread

Prev Next