lib/handsoap/xml_query_front.rb in handsoap-1.1.7 vs lib/handsoap/xml_query_front.rb in handsoap-1.1.8
- old
+ new
@@ -90,10 +90,13 @@
self.first.to_s if self.any?
end
def node_name
self.first.node_name if self.any?
end
+ def node_namespace
+ self.first.node_namespace if self.any?
+ end
def xpath(expression, ns = nil)
self.first.xpath(expression, ns)
end
def /(expression)
self.first.xpath(expression)
@@ -170,10 +173,15 @@
end
# Returns the node name of the current element.
def node_name
raise NotImplementedError.new
end
+ # Returns the node namespace uri of the current element if any, +nil+ otherwise.
+ # Result returned for attribute nodes varies for different drivers, currently.
+ def node_namespace
+ raise NotImplementedError.new
+ end
# Queries the document with XPath, relative to the current element.
#
# +ns+ Should be a Hash of prefix => namespace
#
# Returns a +NodeSelection+
@@ -214,10 +222,17 @@
class LibXMLDriver
include XmlElement
def node_name
@element.name
end
+ def node_namespace
+ if @element.respond_to? :namespaces
+ if namespace = @element.namespaces.namespace
+ namespace.href
+ end
+ end
+ end
def xpath(expression, ns = nil)
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) })
@@ -254,10 +269,17 @@
@element.name
else
@element.class.name.gsub(/.*::([^:]+)$/, "\\1").downcase
end
end
+ def node_namespace
+ if @element.respond_to? :namespace
+ namespace = @element.namespace
+ return if namespace == ''
+ end
+ namespace
+ 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) })
@@ -294,9 +316,12 @@
# http://nokogiri.rubyforge.org/nokogiri/
class NokogiriDriver
include XmlElement
def node_name
@element.name
+ end
+ def node_namespace
+ @element.namespace.href if @element.namespace
end
def xpath(expression, ns = nil)
ns = {} if ns.nil?
ns = @namespaces.merge(ns)
assert_prefixes!(expression, ns)