250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
# File 'lib/xmlutils/xml_doc.rb', line 250
def self.build_xmlnode(element, parent = nil)
attrs = {}
element.attributes.each do |k, attr|
attrs[k.to_sym] = attr.value
end
ns = element.namespace(element.prefix)
attrs[:namespace] = ns if ns && !ns.empty?
text_content = element.children
.select { |c| c.is_a?(XmlUtils::Text) || c.is_a?(XmlUtils::CData) }
.map(&:to_s)
.join
attrs[:text] = text_content unless text_content.strip.empty?
node = XmlNode.new(name: element.name, parent: parent, attributes: attrs)
element.children.select { |c| c.is_a?(XmlUtils::Element) }.each do |child|
build_xmlnode(child, node)
end
node
end
|