module RDF::TriX::Reader::LibXML
LibXML-Ruby implementation of the TriX
reader.
Constants
- OPTIONS
Public Class Methods
library()
click to toggle source
Returns the name of the underlying XML library.
@return [Symbol]
# File lib/rdf/trix/reader/libxml.rb, line 14 def self.library :libxml end
Public Instance Methods
initialize_xml(input, **options)
click to toggle source
Initializes the underlying XML library.
@param [Hash{Symbol => Object}] options @return [void]
# File lib/rdf/trix/reader/libxml.rb, line 23 def initialize_xml(input, **options) require 'libxml' unless defined?(::LibXML) @xml = case input when File then ::LibXML::XML::Document.file(input.path) when IO, StringIO then ::LibXML::XML::Document.io(input) else ::LibXML::XML::Document.string(input.to_s) end end
Protected Instance Methods
element_content(element)
click to toggle source
@private
# File lib/rdf/trix/reader/libxml.rb, line 68 def element_content(element) element.content end
element_elements(element)
click to toggle source
@private
# File lib/rdf/trix/reader/libxml.rb, line 62 def element_elements(element) element.children.select { |node| node.element? } end
find_graphs(&block)
click to toggle source
@private
# File lib/rdf/trix/reader/libxml.rb, line 36 def find_graphs(&block) @xml.find('//trix:graph', OPTIONS).each(&block) end
read_base()
click to toggle source
@private
# File lib/rdf/trix/reader/libxml.rb, line 42 def read_base base = @xml.root.attributes.get_attribute_ns("http://www.w3.org/XML/1998/namespace", "base") if @xml && @xml.root RDF::URI(base.value) if base end
read_graph(graph_element)
click to toggle source
@private
# File lib/rdf/trix/reader/libxml.rb, line 49 def read_graph(graph_element) name = graph_element.children.select { |node| node.element? && node.name.to_s == 'uri' }.first.content.strip rescue nil name ? RDF::URI.intern(name) : nil end
triple_elements(element)
click to toggle source
@private
# File lib/rdf/trix/reader/libxml.rb, line 56 def triple_elements(element) element.find('./trix:triple', OPTIONS) end