Class: Lutaml::Model::XmlAdapter::NokogiriAdapter
- Inherits:
-
XmlDocument
- Object
- XmlDocument
- Lutaml::Model::XmlAdapter::NokogiriAdapter
- Defined in:
- lib/lutaml/model/xml_adapter/nokogiri_adapter.rb
Instance Attribute Summary
Attributes inherited from XmlDocument
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from XmlDocument
#add_to_xml, #add_value, #attribute_definition_for, #attribute_value_for, #attributes, #attributes_hash, #build_attributes, #build_element, #build_namespace_attributes, #build_options_for_nested_elements, #build_unordered_element, #cdata, #children, #declaration, encoding, #handle_nested_elements, #initialize, name_of, #namespace_attributes, namespaced_name_of, #order, order_of, #ordered?, #parse_element, #process_content_mapping, #render_default?, #render_element?, #set_namespace?, #text, text_of, #to_h, type
Constructor Details
This class inherits a constructor from Lutaml::Model::XmlAdapter::XmlDocument
Class Method Details
.parse(xml, options = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb', line 9 def self.parse(xml, = {}) parsed = Nokogiri::XML(xml, nil, encoding(xml, )) @root = NokogiriElement.new(parsed.root) new(@root, parsed.encoding) end |
Instance Method Details
#to_xml(options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb', line 15 def to_xml( = {}) = {} if .key?(:encoding) [:encoding] = [:encoding] unless [:encoding].nil? elsif .key?(:parse_encoding) [:encoding] = [:parse_encoding] else [:encoding] = "UTF-8" end builder = Builder::Nokogiri.build() do |xml| if root.is_a?(Lutaml::Model::XmlAdapter::NokogiriElement) root.build_xml(xml) else mapper_class = [:mapper_class] || @root.class [:xml_attributes] = build_namespace_attributes(mapper_class) build_element(xml, @root, ) end end = {} [:indent] = 2 if [:pretty] xml_data = builder.doc.root.to_xml() [:declaration] ? declaration() + xml_data : xml_data end |