lib/handsoap/xml_query_front.rb in handsoap-1.1.0 vs lib/handsoap/xml_query_front.rb in handsoap-1.1.1
- old
+ new
@@ -180,10 +180,14 @@
#
# See add_namespace
def xpath(expression, ns = nil)
raise NotImplementedError.new
end
+ # Returns a +NodeSelection+
+ def children
+ raise NotImplementedError.new
+ end
# Returns the outer XML for this element.
def to_xml
raise NotImplementedError.new
end
# Returns the outer XML for this element, preserving the original formatting.
@@ -216,10 +220,13 @@
ns = {} if ns.nil?
ns = @namespaces.merge(ns)
assert_prefixes!(expression, ns)
NodeSelection.new(@element.find(expression, ns.map{|k,v| "#{k}:#{v}" }).to_a.map{|node| LibXMLDriver.new(node, ns) })
end
+ def children
+ NodeSelection.new(@element.children.map{|node| LibXMLDriver.new(node) })
+ end
def [](attribute_name)
raise ArgumentError.new unless attribute_name.kind_of? String
@element[attribute_name]
end
def to_xml
@@ -241,18 +248,25 @@
#
# http://www.germane-software.com/software/rexml/
class REXMLDriver
include XmlElement
def node_name
- @element.name
+ if @element.respond_to? :name
+ @element.name
+ else
+ @element.class.name.gsub(/.*::([^:]+)$/, "\\1").downcase
+ end
end
def xpath(expression, ns = nil)
ns = {} if ns.nil?
ns = @namespaces.merge(ns)
assert_prefixes!(expression, ns)
NodeSelection.new(REXML::XPath.match(@element, expression, ns).map{|node| REXMLDriver.new(node, ns) })
end
+ def children
+ NodeSelection.new(@element.children.map{|node| REXMLDriver.new(node) })
+ end
def [](attribute_name)
raise ArgumentError.new unless attribute_name.kind_of? String
@element.attributes[attribute_name]
end
def to_xml
@@ -265,14 +279,14 @@
end
def to_raw
@element.to_s
end
def to_s
- if @element.kind_of? REXML::Attribute
- @element.value
- else
+ if @element.respond_to? :text
@element.text
+ else
+ @element.value
end
end
end
# Driver for +Nokogiri+
@@ -286,9 +300,12 @@
def xpath(expression, ns = nil)
ns = {} if ns.nil?
ns = @namespaces.merge(ns)
assert_prefixes!(expression, ns)
NodeSelection.new(@element.xpath(expression, ns).map{|node| NokogiriDriver.new(node, ns) })
+ end
+ def children
+ NodeSelection.new(@element.children.map{|node| NokogiriDriver.new(node) })
end
def [](attribute_name)
raise ArgumentError.new unless attribute_name.kind_of? String
@element[attribute_name]
end