class OpenSRS::XmlProcessor::Libxml
Public Class Methods
build(data)
click to toggle source
First, builds REXML elements for the inputted data. Then, it will go ahead and build the entire XML document to send to OpenSRS
.
# File lib/opensrs/xml_processor/libxml.rb, line 9 def self.build(data) xml = Document.new xml.root = envelope = Node.new("OPS_envelope") envelope << header = Node.new("header") envelope << body = Node.new("body") header << Node.new("version", "0.9") body << data_block = Node.new("data_block") data_block << encode_data(data, data_block) return xml.to_s end
Protected Class Methods
data_block_element(response)
click to toggle source
# File lib/opensrs/xml_processor/libxml.rb, line 25 def self.data_block_element(response) doc = Parser.string(response).parse return doc.find("//OPS_envelope/body/data_block/*") end
decode_dt_array_data(element)
click to toggle source
# File lib/opensrs/xml_processor/libxml.rb, line 30 def self.decode_dt_array_data(element) dt_array = [] element.children.each do |item| next if item.empty? dt_array[item.attributes["key"].to_i] = decode_data(item) end return dt_array end
decode_dt_assoc_data(element)
click to toggle source
# File lib/opensrs/xml_processor/libxml.rb, line 41 def self.decode_dt_assoc_data(element) dt_assoc = {} element.children.each do |item| next if item.content.strip.empty? dt_assoc[item.attributes["key"]] = decode_data(item) end return dt_assoc end
new_element(element_name, container)
click to toggle source
Accepts two parameters but uses only one; to keep the interface same as other xml parser classes Is that a side effect of Template pattern?
# File lib/opensrs/xml_processor/libxml.rb, line 55 def self.new_element(element_name, container) return Node.new(element_name.to_s) end