Class: Handsoap::XmlQueryFront::NokogiriDriver

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

Overview

Driver for Nokogiri

nokogiri.rubyforge.org/nokogiri/

Instance Method Summary (collapse)

Methods included from XmlElement

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

Instance Method Details

- (Object) [](attribute_name)

Raises:

  • (ArgumentError)


345
346
347
348
# File 'lib/handsoap/xml_query_front.rb', line 345

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

- (Object) children



342
343
344
# File 'lib/handsoap/xml_query_front.rb', line 342

def children
  NodeSelection.new(@element.children.map{|node| NokogiriDriver.new(node) })
end

- (Object) node_name



330
331
332
# File 'lib/handsoap/xml_query_front.rb', line 330

def node_name
  @element.name
end

- (Object) node_namespace



333
334
335
# File 'lib/handsoap/xml_query_front.rb', line 333

def node_namespace
  @element.namespace.href if @element.namespace
end

- (Object) to_raw



352
353
354
# File 'lib/handsoap/xml_query_front.rb', line 352

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

- (Object) to_s



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/handsoap/xml_query_front.rb', line 355

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

- (Object) to_xml



349
350
351
# File 'lib/handsoap/xml_query_front.rb', line 349

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

- (Object) xpath(expression, ns = nil)



336
337
338
339
340
341
# File 'lib/handsoap/xml_query_front.rb', line 336

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