lib/atom/xml/parser.rb in ratom-0.2.2 vs lib/atom/xml/parser.rb in ratom-0.3.0
- old
+ new
@@ -4,10 +4,11 @@
# to use, modify, or create derivate works.
# Please contact info@peerworks.org for further information.
#
require 'net/http'
+require 'time'
# Just a couple methods form transforming strings
unless defined?(ActiveSupport)
class String # :nodoc:
def singularize
@@ -34,19 +35,21 @@
def parse(xml, options = {})
starting_depth = xml.depth
loop do
case xml.node_type
when XML::Reader::TYPE_ELEMENT
- if element_specs.include?(xml.local_name)
+ if element_specs.include?(xml.local_name) && [Atom::NAMESPACE, Atom::Pub::NAMESPACE].include?(xml.namespace_uri)
element_specs[xml.local_name].parse(self, xml)
elsif attributes.any?
while (xml.move_to_next_attribute == 1)
if attributes.include?(xml.name)
# Support attribute names with namespace prefixes
self.send("#{xml.name.sub(/:/, '_')}=", xml.value)
end
end
+ elsif self.respond_to?(:simple_extensions)
+ self[xml.namespace_uri, xml.local_name] << xml.read_string
end
end
break unless !options[:once] && xml.next == 1 && xml.depth >= starting_depth
end
end
@@ -108,9 +111,24 @@
self.class.attributes.each do |attribute|
if value = self.send("#{attribute.sub(/:/, '_')}")
if value != 0
node[attribute] = value.to_s
+ end
+ end
+ end
+
+ if self.respond_to?(:simple_extensions) && self.simple_extensions
+ self.simple_extensions.each do |name, value_array|
+ if name =~ /\{(.*),(.*)\}/
+ value_array.each do |value|
+ ext = XML::Node.new($2)
+ ext['xmlns'] = $1
+ ext << value
+ node << ext
+ end
+ else
+ STDERR.print "Couldn't split #{name}"
end
end
end
unless nodeonly