Module: RDF::TriX::Writer::REXML

Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-trix-7eafacbcb8c1/lib/rdf/trix/writer/rexml.rb

Overview

REXML implementation of the TriX writer.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.librarySymbol

Returns the name of the underlying XML library.

Returns:



12
13
14
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-trix-7eafacbcb8c1/lib/rdf/trix/writer/rexml.rb', line 12

def self.library
  :rexml
end

Instance Method Details

#create_comment(text) ⇒ REXML::Comment

Creates an XML comment element with the given text.

Parameters:

Returns:

  • (REXML::Comment)


72
73
74
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-trix-7eafacbcb8c1/lib/rdf/trix/writer/rexml.rb', line 72

def create_comment(text)
  ::REXML::Comment.new(text.to_s)
end

#create_element(name, content = nil, attributes = {}) {|element| ... } ⇒ REXML::Element

Creates an XML element of the given name, with optional given content and attributes.

Parameters:

Yields:

  • (element)

Yield Parameters:

Returns:



86
87
88
89
90
91
92
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-trix-7eafacbcb8c1/lib/rdf/trix/writer/rexml.rb', line 86

def create_element(name, content = nil, attributes = {}, &block)
  element = ::REXML::Element.new(name.to_s, nil, @xml.context)
  attributes.each { |k, v| element.add_attribute(k.to_s, v) }
  element.text = content.to_s unless content.nil?
  block.call(element) if block_given?
  element
end

#create_graph(name = nil) {|element| ... } ⇒ REXML::Element

Creates an XML graph element with the given name.

Parameters:

Yields:

  • (element)

Yield Parameters:

Returns:



56
57
58
59
60
61
62
63
64
65
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-trix-7eafacbcb8c1/lib/rdf/trix/writer/rexml.rb', line 56

def create_graph(name = nil, &block)
  graph = @trix.add_element('graph')
  case name
    when nil then nil
    when RDF::Node then graph.add_element('id').text = name.to_s # non-standard
    else graph.add_element('uri').text = name.to_s
  end
  block.call(graph) if block_given?
  graph
end

#initialize_xml(options = {})

This method returns an undefined value.

Initializes the underlying XML library.

Parameters:



21
22
23
24
25
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-trix-7eafacbcb8c1/lib/rdf/trix/writer/rexml.rb', line 21

def initialize_xml(options = {})
  require 'rexml/document' unless defined?(::REXML)
  @xml = ::REXML::Document.new(nil, :attribute_quote => :quote)
  @xml << ::REXML::XMLDecl.new(::REXML::XMLDecl::DEFAULT_VERSION, @encoding)
end

#write_epilogue

This method returns an undefined value.

Outputs the TriX document.



40
41
42
43
44
45
46
47
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-trix-7eafacbcb8c1/lib/rdf/trix/writer/rexml.rb', line 40

def write_epilogue
  formatter = ::REXML::Formatters::Pretty.new((@options[:indent] || 2).to_i, false)
  formatter.compact = true
  formatter.write(@xml, @output)
  puts # add a line break after the last line
  @xml = @trix = nil
  super
end

#write_prologue

This method returns an undefined value.

Generates the TriX root element.



31
32
33
34
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-trix-7eafacbcb8c1/lib/rdf/trix/writer/rexml.rb', line 31

def write_prologue
  @trix = @xml.add_element('TriX', 'xmlns' => Format::XMLNS)
  super
end