Top Level Namespace
Defined Under Namespace
Modules: ApplicationCable, ApplicationHelper, BannerHelper, EmulatorHelper, Mediaflux, ProjectHelper, TigerData
Classes: ActivateProjectJob, Affiliation, ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Breadcrumb, FileInventoryCleanupJob, FileInventoryJob, FileInventoryRequest, MediafluxChannel, MediafluxDuplicateNamespaceError, MediafluxInfoController, MediafluxScriptFactory, MediafluxStatus, OrganizationsController, PULDatacite, Project, ProjectAccumulator, ProjectDashboardPresenter, ProjectJobService, ProjectMediaflux, ProjectMetadata, ProjectShowPresenter, ProjectValidator, ProjectsController, ProvenanceEvent, ReadOnlyUser, Store, SystemUser, TestAssetGenerator, TestProjectGenerator, TigerdataMailer, TigerdataSchema, User, UserRequest, VersionFooter, WelcomeController
Constant Summary
collapse
- TYPENAMES =
frozen_string_literal: true
{ 1 => "element", 2 => "attribute", 3 => "text", 4 => "cdata", 8 => "comment" }.freeze
Instance Method Summary
collapse
Instance Method Details
#xml_doc_to_hash(document) ⇒ Object
26
27
28
|
# File 'lib/xml_utilities.rb', line 26
def xml_doc_to_hash(document)
xml_node_to_hash(document.root)
end
|
#xml_doc_to_html(document) ⇒ Object
30
31
32
33
34
|
# File 'lib/xml_utilities.rb', line 30
def xml_doc_to_html(document)
as_hash = xml_doc_to_hash(document)
as_yaml = YAML.dump(as_hash).gsub(/\A---\n/, "")
"<pre>#{CGI.escapeHTML(as_yaml)}</pre>"
end
|
#xml_node_to_hash(node) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/xml_utilities.rb', line 7
def xml_node_to_hash(node)
h = {}
h[:name] = node.name
if node.namespace
h[:nshref] = node.namespace.href
h[:nsprefix] = node.namespace.prefix
end
h[:text] = node.text unless node.text.empty?
h[:attributes] = node.attribute_nodes.map { |attr_node| xml_node_to_hash(attr_node) } if node.element? && !node.attribute_nodes.empty?
h[:subelements] = node.children.map { |child_node| xml_node_to_hash(child_node) } if node.element? && !node.children.empty?
h
end
|