Class: Uniword::Wordprocessingml::Settings

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/uniword/wordprocessingml/settings.rb

Overview

Document settings

Generated from OOXML schema: wordprocessingml.yml Element: <w:settings>

Class Method Summary collapse

Class Method Details

.from_xml(xml_content) ⇒ Object

Override from_xml to manually deserialize w15:docId which has the same element name as w14:docId and can’t be distinguished by map_element alone. Note: Both docId elements have their values captured via map_element (w14) and from_xml (w15). The w15:docId’s GUID is preserved in the model.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/uniword/wordprocessingml/settings.rb', line 157

def self.from_xml(xml_content)
  settings = super

  doc = Nokogiri::XML(xml_content)
  doc_ids = doc.xpath('//*[local-name()="docId"]')
  doc_ids.each do |elem|
    ns_uri = elem.namespace&.href
    val = elem.attributes["val"]&.value
    next unless val

    if (ns_uri == "http://schemas.microsoft.com/office/word/2012/wordml") && !settings.w15_doc_id&.val
      # w15:docId - manually deserialize since map_element captures w14:docId
      settings.w15_doc_id = W15DocId.new(val: val)
    end
    # w14:docId is captured by map_element 'docId', no action needed
  end

  settings
end