/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. # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
  4. # redistribute it and/or modify it under the same terms of Ruby's license;
  5. # either the dual license version in 2003, or any later version.
  6. require 'xsd/xmlparser/parser'
  7. module XSD
  8. module XMLParser
  9. def create_parser(host, opt)
  10. XSD::XMLParser::Parser.create_parser(host, opt)
  11. end
  12. module_function :create_parser
  13. # $1 is necessary.
  14. NSParseRegexp = Regexp.new('^xmlns:?(.*)$')
  15. def filter_ns(ns, attrs)
  16. return attrs if attrs.nil? or attrs.empty?
  17. newattrs = {}
  18. attrs.each do |key, value|
  19. if (NSParseRegexp =~ key)
  20. # '' means 'default namespace'.
  21. tag = $1 || ''
  22. ns.assign(value, tag)
  23. else
  24. newattrs[key] = value
  25. end
  26. end
  27. newattrs
  28. end
  29. module_function :filter_ns
  30. end
  31. end
  32. # Try to load XML processor.
  33. loaded = false
  34. [
  35. 'xsd/xmlparser/xmlparser',
  36. 'xsd/xmlparser/xmlscanner',
  37. 'xsd/xmlparser/rexmlparser',
  38. ].each do |lib|
  39. begin
  40. require lib
  41. loaded = true
  42. break
  43. rescue LoadError
  44. end
  45. end
  46. unless loaded
  47. raise RuntimeError.new("XML processor module not found.")
  48. end