Module: Peanuts::XML::LibXML

Defined in:
lib/peanuts/xml/libxml.rb

Defined Under Namespace

Classes: Reader, Schema, Writer

Class Method Summary collapse

Class Method Details

.libxml_opt(options, default = {}) ⇒ Object



12
13
14
15
# File 'lib/peanuts/xml/libxml.rb', line 12

def self.libxml_opt(options, default = {})
  h = default.merge(options)
  h.update(h.from_namespace!(:libxml))
end

.schema(schema_type, source) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/peanuts/xml/libxml.rb', line 211

def self.schema(schema_type, source)
  schema_class = case schema_type
  when :xml_schema
    ::LibXML::XML::Schema
  when :relax_ng
    ::LibXML::XML::RelaxNG
  else
    raise ArgumentError, "unrecognized schema type #{schema_type}"
  end
  schema = case source
  when IO
    schema_class.string(source.read)
  when URI
    schema_class.new(source.to_s)
  when ::LibXML::XML::Document
    schema_class.document(source)
  else
    schema_class.string(source)
  end

  Schema.new(schema_type, schema)
end