class Lutaml::Model::XmlAdapter::OgaAdapter
def self.parse(xml)
def self.parse(xml) parsed = Oga.parse_xml(xml) root = OgaElement.new(parsed) new(root) end
def build_attributes(attributes)
def build_attributes(attributes) attributes.transform_values(&:value) end
def build_element(builder, element, options = {})
def build_element(builder, element, options = {}) attributes = build_attributes(element.attributes) builder.element(element.name, attributes) do element.children.each do |child| build_element(builder, child, options) end builder.text(element.text) if element.text end end
def parse_element(element)
def parse_element(element) result = { "_text" => element.text } element.children.each do |child| next if child.is_a?(Oga::XML::Text) result[child.name] ||= [] result[child.name] << parse_element(child) end result end
def to_h
def to_h { @root.name => parse_element(@root) } end
def to_xml(options = {})
def to_xml(options = {}) builder = Oga::XML::Builder.new build_element(builder, @root, options) xml_data = builder.to_xml options[:declaration] ? declaration(options) + xml_data : xml_data end