lib/xsd_reader/xml.rb in xsd-reader-0.0.1 vs lib/xsd_reader/xml.rb in xsd-reader-0.1.0
- old
+ new
@@ -2,12 +2,24 @@
# require 'open-uri'
module XsdReader
class XML
- include Shared
+ attr_reader :options
+ def initialize(_opts = {})
+ @options = _opts || {}
+ raise "#{self.class.to_s}.new expects a hash parameter" if !@options.is_a?(Hash)
+ end
+
+ def logger
+ return @logger if @logger
+ @logger ||= options[:logger] || Logger.new(STDOUT)
+ @logger.level = Logger::WARN
+ return @logger
+ end
+
def xsd_from_uri
# @xsd_from_uri ||= options[:xsd_uri].nil ? nil : open(options[:xsd_uri])
end
def xsd_from_file
@@ -20,19 +32,40 @@
def doc
@doc ||= Nokogiri.XML(xml)
end
+ def node
+ nil
+ end
+
def schema_node
doc.root.name == 'schema' ? doc.root : nil
end
def schema
- node_to_object(schema_node)
+ @schema ||= Schema.new(self.options.merge(:node => schema_node, :logger => logger))
end
+ # forwards most functions to schema
+ def [](*args)
+ schema[*args]
+ end
+
def elements
schema.elements
+ end
+
+ def imports
+ schema.imports
+ end
+
+ def simple_types
+ schema.simple_types
+ end
+
+ def schema_for_namespace(_ns)
+ schema.schema_for_namespace(_ns)
end
end # class XML
end # module XsdReader
\ No newline at end of file