PageRenderTime 72ms CodeModel.GetById 63ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/xsd/xmlparser.rb

http://github.com/agross/netopenspace
Ruby | 61 lines | 40 code | 13 blank | 8 comment | 3 complexity | f4d2649c84b0e96045007da6f3693389 MD5 | raw file
 1# XSD4R - XML Instance parser library.
 2# Copyright (C) 2002, 2003  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
 3
 4# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
 5# redistribute it and/or modify it under the same terms of Ruby's license;
 6# either the dual license version in 2003, or any later version.
 7
 8
 9require 'xsd/xmlparser/parser'
10
11
12module XSD
13
14
15module XMLParser
16  def create_parser(host, opt)
17    XSD::XMLParser::Parser.create_parser(host, opt)
18  end
19  module_function :create_parser
20
21  # $1 is necessary.
22  NSParseRegexp = Regexp.new('^xmlns:?(.*)$')
23
24  def filter_ns(ns, attrs)
25    return attrs if attrs.nil? or attrs.empty?
26    newattrs = {}
27    attrs.each do |key, value|
28      if (NSParseRegexp =~ key)
29	# '' means 'default namespace'.
30	tag = $1 || ''
31	ns.assign(value, tag)
32      else
33	newattrs[key] = value
34      end
35    end
36    newattrs
37  end
38  module_function :filter_ns
39end
40
41
42end
43
44
45# Try to load XML processor.
46loaded = false
47[
48  'xsd/xmlparser/xmlparser',
49  'xsd/xmlparser/xmlscanner',
50  'xsd/xmlparser/rexmlparser',
51].each do |lib|
52  begin
53    require lib
54    loaded = true
55    break
56  rescue LoadError
57  end
58end
59unless loaded
60  raise RuntimeError.new("XML processor module not found.")
61end