Module: Lutaml::Xml::Adapter::XmlParser
- Included in:
- BaseAdapter
- Defined in:
- lib/lutaml/xml/adapter/xml_parser.rb
Overview
Class methods for parsing XML input.
Extracted from BaseAdapter — parsing is a distinct lifecycle phase with no instance state dependency.
Subclasses must define:
-
MOXML_ADAPTER — Moxml adapter class for parsing
-
PARSED_ELEMENT_CLASS — element wrapper class
-
PARSE_ERROR_CLASS — error class to rescue (nil to skip)
-
EMPTY_DOCUMENT_ERROR_MESSAGE — error message for empty docs
-
EMPTY_DOCUMENT_ERROR_TYPE — :invalid_format or :parse_exception
Instance Method Summary collapse
Instance Method Details
#parse(xml, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lutaml/xml/adapter/xml_parser.rb', line 18 def parse(xml, = {}) parse_encoding = encoding(xml, ) raw_xml = xml xml = normalize_xml_for_parse(xml) parsed = parse_with_moxml(xml, parse_encoding) root_element = parsed.root raise_empty_document_error if root_element.nil? root = self::PARSED_ELEMENT_CLASS.new(root_element) doc_pis = extract_document_processing_instructions(parsed) root.processing_instructions = doc_pis unless doc_pis.empty? new(root, parse_encoding, **(raw_xml)) end |