/usr/lib/ruby/vendor_ruby/multi_xml/parsers/libxml2_parser.rb is in ruby-multi-xml 0.5.4-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | module MultiXml
module Parsers
module Libxml2Parser #:nodoc:
# Convert XML document to hash
#
# node::
# The XML node object to convert to a hash.
#
# hash::
# Hash to merge the converted element into.
def node_to_hash(node, hash={})
node_hash = {MultiXml::CONTENT_ROOT => ''}
name = node_name(node)
# Insert node hash into parent hash correctly.
case hash[name]
when Array then hash[name] << node_hash
when Hash then hash[name] = [hash[name], node_hash]
when nil then hash[name] = node_hash
end
# Handle child elements
each_child(node) do |c|
if c.element?
node_to_hash(c, node_hash)
elsif c.text? || c.cdata?
node_hash[MultiXml::CONTENT_ROOT] << c.content
end
end
# Remove content node if it is empty
if node_hash[MultiXml::CONTENT_ROOT].strip.empty?
node_hash.delete(MultiXml::CONTENT_ROOT)
end
# Handle attributes
each_attr(node) {|a| node_hash[node_name(a)] = a.value }
hash
end
# Parse an XML Document IO into a simple hash.
# xml::
# XML Document IO to parse
def parse(xml)
raise NotImplementedError, "inheritor should define #{__method__}"
end
# :stopdoc:
private
def each_child(*args)
raise NotImplementedError, "inheritor should define #{__method__}"
end
def each_attr(*args)
raise NotImplementedError, "inheritor should define #{__method__}"
end
def node_name(*args)
raise NotImplementedError, "inheritor should define #{__method__}"
end
end
end
end
|