Module: Moxml

Defined in:
lib/moxml/entity_registry_opal_data.rb,
lib/moxml.rb,
lib/moxml/sax.rb,
lib/moxml/c14n.rb,
lib/moxml/node.rb,
lib/moxml/text.rb,
lib/moxml/cdata.rb,
lib/moxml/error.rb,
lib/moxml/xpath.rb,
lib/moxml/config.rb,
lib/moxml/entity.rb,
lib/moxml/adapter.rb,
lib/moxml/builder.rb,
lib/moxml/comment.rb,
lib/moxml/context.rb,
lib/moxml/doctype.rb,
lib/moxml/element.rb,
lib/moxml/version.rb,
lib/moxml/document.rb,
lib/moxml/node_set.rb,
lib/moxml/attribute.rb,
lib/moxml/c14n/node.rb,
lib/moxml/namespace.rb,
lib/moxml/signature.rb,
lib/moxml/xml_utils.rb,
lib/moxml/adapter/ox.rb,
lib/moxml/c14n/nodes.rb,
lib/moxml/adapter/oga.rb,
lib/moxml/c14n/writer.rb,
lib/moxml/declaration.rb,
lib/moxml/sax/handler.rb,
lib/moxml/xml_emitter.rb,
lib/moxml/xpath/cache.rb,
lib/moxml/xpath/lexer.rb,
lib/moxml/adapter/base.rb,
lib/moxml/materializer.rb,
lib/moxml/xpath/engine.rb,
lib/moxml/xpath/errors.rb,
lib/moxml/xpath/parser.rb,
lib/moxml/adapter/rexml.rb,
lib/moxml/xpath/context.rb,
lib/moxml/adapter/libxml.rb,
lib/moxml/c14n/exclusive.rb,
lib/moxml/c14n/processor.rb,
lib/moxml/xpath/ast/node.rb,
lib/moxml/xpath/compiler.rb,
lib/moxml/adapter/leptris.rb,
lib/moxml/c14n/data_model.rb,
lib/moxml/entity/restorer.rb,
lib/moxml/entity_registry.rb,
lib/moxml/signature/model.rb,
lib/moxml/xpath/ruby/node.rb,
lib/moxml/adapter/nokogiri.rb,
lib/moxml/document_builder.rb,
lib/moxml/entity/reference.rb,
lib/moxml/entity_reference.rb,
lib/moxml/signature/errors.rb,
lib/moxml/signature/parser.rb,
lib/moxml/signature/signer.rb,
lib/moxml/xpath/conversion.rb,
lib/moxml/adapter/headed_ox.rb,
lib/moxml/c14n/inclusive_10.rb,
lib/moxml/c14n/inclusive_11.rb,
lib/moxml/native_attachment.rb,
lib/moxml/sax/block_handler.rb,
lib/moxml/xml_utils/encoder.rb,
lib/moxml/attribute_resolver.rb,
lib/moxml/signature/verifier.rb,
lib/moxml/sax/element_handler.rb,
lib/moxml/c14n/nodes/root_node.rb,
lib/moxml/c14n/nodes/text_node.rb,
lib/moxml/signature/algorithms.rb,
lib/moxml/signature/serializer.rb,
lib/moxml/xpath/ruby/generator.rb,
lib/moxml/adapter/customized_ox.rb,
lib/moxml/c14n/xml_base_handler.rb,
lib/moxml/adapter/customized_oga.rb,
lib/moxml/c14n/attribute_handler.rb,
lib/moxml/c14n/character_encoder.rb,
lib/moxml/c14n/namespace_context.rb,
lib/moxml/c14n/namespace_handler.rb,
lib/moxml/native_attachment/opal.rb,
lib/moxml/processing_instruction.rb,
lib/moxml/sax/namespace_splitter.rb,
lib/moxml/c14n/nodes/comment_node.rb,
lib/moxml/c14n/nodes/element_node.rb,
lib/moxml/signature/key_extractor.rb,
lib/moxml/adapter/customized_rexml.rb,
lib/moxml/native_attachment/native.rb,
lib/moxml/signature/model/key_info.rb,
lib/moxml/adapter/customized_libxml.rb,
lib/moxml/c14n/nodes/attribute_node.rb,
lib/moxml/c14n/nodes/namespace_node.rb,
lib/moxml/signature/algorithms/sha1.rb,
lib/moxml/signature/model/key_value.rb,
lib/moxml/signature/model/reference.rb,
lib/moxml/signature/model/signature.rb,
lib/moxml/signature/model/transform.rb,
lib/moxml/adapter/customized_leptris.rb,
lib/moxml/adapter/customized_ox/text.rb,
lib/moxml/signature/model/transforms.rb,
lib/moxml/signature/reference_result.rb,
lib/moxml/signature/algorithms/sha224.rb,
lib/moxml/signature/algorithms/sha256.rb,
lib/moxml/signature/algorithms/sha384.rb,
lib/moxml/signature/algorithms/sha512.rb,
lib/moxml/signature/model/signed_info.rb,
lib/moxml/signature/algorithms/dsa_sha.rb,
lib/moxml/signature/reference_resolver.rb,
lib/moxml/signature/transform_pipeline.rb,
lib/moxml/signature/algorithms/hmac_sha.rb,
lib/moxml/signature/model/digest_method.rb,
lib/moxml/signature/model/key/x509_data.rb,
lib/moxml/signature/verification_result.rb,
lib/moxml/adapter/customized_libxml/node.rb,
lib/moxml/adapter/customized_libxml/text.rb,
lib/moxml/signature/algorithms/ecdsa_sha.rb,
lib/moxml/signature/model/object_element.rb,
lib/moxml/adapter/customized_libxml/cdata.rb,
lib/moxml/adapter/customized_ox/attribute.rb,
lib/moxml/adapter/customized_ox/namespace.rb,
lib/moxml/signature/model/key/x509_digest.rb,
lib/moxml/signature/model/signature_value.rb,
lib/moxml/signature/algorithms/digest_base.rb,
lib/moxml/signature/algorithms/exc_c14n_10.rb,
lib/moxml/signature/model/algorithm_method.rb,
lib/moxml/signature/model/key/ec_key_value.rb,
lib/moxml/adapter/customized_libxml/comment.rb,
lib/moxml/adapter/customized_libxml/element.rb,
lib/moxml/signature/model/key/dsa_key_value.rb,
lib/moxml/signature/model/key/rsa_key_value.rb,
lib/moxml/adapter/customized_leptris/doctype.rb,
lib/moxml/adapter/customized_rexml/formatter.rb,
lib/moxml/adapter/libxml/entity_ref_registry.rb,
lib/moxml/signature/algorithms/rsa_pkcs1_sha.rb,
lib/moxml/signature/algorithms/transform_base.rb,
lib/moxml/adapter/customized_oga/xml_generator.rb,
lib/moxml/signature/single_verification_result.rb,
lib/moxml/adapter/customized_libxml/declaration.rb,
lib/moxml/adapter/customized_oga/entity_decoder.rb,
lib/moxml/signature/algorithms/base64_transform.rb,
lib/moxml/adapter/customized_leptris/declaration.rb,
lib/moxml/adapter/customized_leptris/document_pi.rb,
lib/moxml/adapter/customized_oga/xml_declaration.rb,
lib/moxml/adapter/customized_ox/entity_reference.rb,
lib/moxml/c14n/nodes/processing_instruction_node.rb,
lib/moxml/signature/algorithms/inclusive_c14n_10.rb,
lib/moxml/signature/algorithms/inclusive_c14n_11.rb,
lib/moxml/signature/model/key/x509_issuer_serial.rb,
lib/moxml/adapter/customized_leptris/text_segment.rb,
lib/moxml/adapter/customized_oga/raw_value_override.rb,
lib/moxml/adapter/customized_rexml/entity_reference.rb,
lib/moxml/adapter/customized_libxml/entity_reference.rb,
lib/moxml/signature/algorithms/canonicalization_base.rb,
lib/moxml/signature/algorithms/signature_method_base.rb,
lib/moxml/adapter/customized_leptris/entity_reference.rb,
lib/moxml/adapter/customized_libxml/processing_instruction.rb,
lib/moxml/signature/algorithms/enveloped_signature_transform.rb,
sig/moxml.rbs

Overview

monkey patch the Oga generator because it's not configurable https://github.com/yorickpeterse/oga/blob/main/lib/oga/xml/generator.rb

Defined Under Namespace

Modules: Adapter, AttributeResolver, C14n, Entity, Materializer, SAX, Signature, XPath, XmlEmitter, XmlUtils Classes: AdapterError, Attribute, Builder, Cdata, Comment, Config, Context, Declaration, Doctype, Document, DocumentBuilder, DocumentStructureError, Element, EntityReference, EntityRegistry, Error, Namespace, NamespaceError, NativeAttachment, Node, NodeSet, NotImplementedError, ParseError, ProcessingInstruction, Text, ValidationError, XPathError

Constant Summary collapse

VERSION =

Returns:

"0.5.9"

Class Method Summary collapse

Class Method Details

.configure {|Config.default| ... } ⇒ Object

Yields:



15
16
17
# File 'lib/moxml.rb', line 15

def configure
  yield Config.default if block_given?
end

.new(adapter = nil, &block) ⇒ Object



5
6
7
8
9
# File 'lib/moxml.rb', line 5

def new(adapter = nil, &block)
  context = Context.new(adapter)
  context.config.instance_eval(&block) if block
  context
end

.parse(xml, adapter: nil, **options) ⇒ Object



11
12
13
# File 'lib/moxml.rb', line 11

def parse(xml, adapter: nil, **options)
  Context.new(adapter).parse(xml, options)
end

.preprocess_entities(xml) ⇒ Object



57
58
59
# File 'lib/moxml.rb', line 57

def preprocess_entities(xml)
  Adapter::Base.preprocess_entities(xml)
end

.restore_entities(text) ⇒ Object



61
62
63
# File 'lib/moxml.rb', line 61

def restore_entities(text)
  Adapter::Base.restore_entities(text)
end

.with_config(adapter_name = nil, strict_parsing = nil, default_encoding = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/moxml.rb', line 19

def with_config(adapter_name = nil, strict_parsing = nil,
                default_encoding = nil)
  original = Config.default
  saved_values = {
    adapter: original.adapter_name,
    strict_parsing: original.strict_parsing,
    default_encoding: original.default_encoding,
    default_indent: original.default_indent,
    default_line_ending: original.default_line_ending,
    entity_load_mode: original.entity_load_mode,
    restore_entities: original.restore_entities,
    namespace_validation_mode: original.namespace_validation_mode,
    entity_restoration_mode: original.entity_restoration_mode,
    preload_entity_sets: original.preload_entity_sets.dup,
  }

  configure do |config|
    config.adapter = adapter_name unless adapter_name.nil?
    config.strict_parsing = strict_parsing unless strict_parsing.nil?
    config.default_encoding = default_encoding unless default_encoding.nil?
  end

  yield if block_given?
ensure
  configure do |config|
    config.adapter = saved_values[:adapter]
    config.strict_parsing = saved_values[:strict_parsing]
    config.default_encoding = saved_values[:default_encoding]
    config.default_indent = saved_values[:default_indent]
    config.default_line_ending = saved_values[:default_line_ending]
    config.entity_load_mode = saved_values[:entity_load_mode]
    config.restore_entities = saved_values[:restore_entities]
    config.namespace_validation_mode = saved_values[:namespace_validation_mode]
    config.entity_restoration_mode = saved_values[:entity_restoration_mode]
    config.preload_entity_sets = saved_values[:preload_entity_sets]
  end
end