Class: Handsoap::XmlQueryFront::NokogiriDriver

Inherits:
Object
  • Object
show all
Includes:
BaseDriver
Defined in:
lib/handsoap/xml_query_front.rb

Overview

Driver for Nokogiri

nokogiri.rubyforge.org/nokogiri/

Instance Method Summary collapse

Methods included from BaseDriver

#/, #add_namespace, #assert_prefixes!, #initialize, #native_element, #to_boolean, #to_date, #to_f, #to_i

Instance Method Details

#[](attribute_name) ⇒ Object

Raises:

  • (ArgumentError)


287
288
289
290
# File 'lib/handsoap/xml_query_front.rb', line 287

def [](attribute_name)
  raise ArgumentError.new unless attribute_name.kind_of? String
  @element[attribute_name]
end

#node_nameObject



278
279
280
# File 'lib/handsoap/xml_query_front.rb', line 278

def node_name
  @element.name
end

#to_rawObject



294
295
296
# File 'lib/handsoap/xml_query_front.rb', line 294

def to_raw
  @element.serialize(:encoding => 'UTF-8', :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML)
end

#to_sObject



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/handsoap/xml_query_front.rb', line 297

def to_s
  if @element.kind_of?(Nokogiri::XML::Text) || @element.kind_of?(Nokogiri::XML::CDATA)
    element = @element
  elsif @element.kind_of?(Nokogiri::XML::Attr)
    return @element.value
  else
    element = @element.children.first
  end
  return if element.nil?
  # This looks messy because it is .. Nokogiri's interface is in a flux
  if element.kind_of?(Nokogiri::XML::CDATA)
    element.serialize(:encoding => 'UTF-8').gsub(/^<!\[CDATA\[/, "").gsub(/\]\]>$/, "")
  else
    element.serialize(:encoding => 'UTF-8').gsub('&lt;', '<').gsub('&gt;', '>').gsub('&quot;', '"').gsub('&apos;', "'").gsub('&amp;', '&')
  end
end

#to_xmlObject



291
292
293
# File 'lib/handsoap/xml_query_front.rb', line 291

def to_xml
  @element.serialize(:encoding => 'UTF-8')
end

#xpath(expression, ns = nil) ⇒ Object



281
282
283
284
285
286
# File 'lib/handsoap/xml_query_front.rb', line 281

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