Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/branches/1_5/lib/xsd/xmlparser.rb

Revision 1956, 1.6 kB (checked in by nahi, 1 year ago)
  • soap4r's XML namespace handler did not handle xmlns="" correctly. it means 'no default namespace'. closes #421.
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 # XSD4R - XML Instance parser library.
2 # Copyright (C) 2000-2007  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
9 require 'xsd/xmlparser/parser'
10
11
12 module XSD
13
14
15 module 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:?(.*)$', nil, 'NONE')
23
24   def filter_ns(ns, attrs)
25     ns_updated = false
26     if attrs.nil? or attrs.empty?
27       return [ns, attrs]
28     end
29     newattrs = {}
30     attrs.each do |key, value|
31       if NSParseRegexp =~ key
32         unless ns_updated
33           ns = ns.clone_ns
34           ns_updated = true
35         end
36         # tag == '' means 'default namespace'
37         # value == '' means 'no default namespace'
38         tag = $1 || ''
39         ns.assign(value, tag)
40       else
41         newattrs[key] = value
42       end
43     end
44     return [ns, newattrs]
45   end
46   module_function :filter_ns
47 end
48
49
50 end
51
52
53 # Try to load XML processor.
54 loaded = false
55 [
56   'xsd/xmlparser/xmlparser',
57   'xsd/xmlparser/xmlscanner',
58   'xsd/xmlparser/rexmlparser',
59 ].each do |lib|
60   begin
61     require lib
62     # XXX: for a workaround of rubygems' require inconsistency
63     # XXX: MUST BE REMOVED IN THE FUTURE
64     name = lib.sub(/^.*\//, '')
65     raise LoadError unless XSD::XMLParser.constants.find { |c|
66       c.downcase == name
67     }
68     loaded = true
69     break
70   rescue LoadError
71   end
72 end
73 unless loaded
74   raise RuntimeError.new("XML processor module not found.")
75 end
Note: See TracBrowser for help on using the browser.