Module: Handsoap::XmlQueryFront::XmlElement

Included in:
LibXMLDriver, NokogiriDriver, REXMLDriver
Defined in:
lib/handsoap/xml_query_front.rb

Overview

Wraps the underlying (native) xml driver, and provides a uniform interface.

Instance Method Summary collapse

Instance Method Details

#/(expression) ⇒ Object

alias of xpath



190
191
192
# File 'lib/handsoap/xml_query_front.rb', line 190

def /(expression)
  self.xpath(expression)
end

#[](attribute_name) ⇒ Object

Returns the attribute value of the underlying element.

Shortcut for:

(node/"@attribute_name").to_s

Raises:

  • (NotImplementedError)


198
199
200
# File 'lib/handsoap/xml_query_front.rb', line 198

def [](attribute_name)
  raise NotImplementedError.new
end

#add_namespace(prefix, uri) ⇒ Object

Registers a prefix to refer to a namespace.

You can either register a nemspace with this function or pass it explicitly to the xpath method.



114
115
116
# File 'lib/handsoap/xml_query_front.rb', line 114

def add_namespace(prefix, uri)
  @namespaces[prefix] = uri
end

#assert_prefixes!(expression, ns) ⇒ Object

Checks that an xpath-query doesn’t refer to any undefined prefixes in ns



118
119
120
121
122
# File 'lib/handsoap/xml_query_front.rb', line 118

def assert_prefixes!(expression, ns)
  expression.scan(/([a-zA-Z_][a-zA-Z0-9_.-]*):[^:]+/).map{|m| m[0] }.each do |prefix|
    raise "Undefined prefix '#{prefix}' in #{ns.inspect}" if ns[prefix].nil?
  end
end

#initialize(element, namespaces = {}) ⇒ Object



107
108
109
110
# File 'lib/handsoap/xml_query_front.rb', line 107

def initialize(element, namespaces = {})
  @element = element
  @namespaces = namespaces
end

#native_elementObject

Returns the underlying native element.

You shouldn’t need to use this, since doing so would void portability.



164
165
166
# File 'lib/handsoap/xml_query_front.rb', line 164

def native_element
  @element
end

#node_nameObject

Returns the node name of the current element.

Raises:

  • (NotImplementedError)


168
169
170
# File 'lib/handsoap/xml_query_front.rb', line 168

def node_name
  raise NotImplementedError.new
end

#to_booleanObject

Returns the value of the element as an boolean.

See to_s



142
143
144
145
146
# File 'lib/handsoap/xml_query_front.rb', line 142

def to_boolean
  t = self.to_s
  return if t.nil?
  t.downcase == 'true'
end

#to_dateObject

Returns the value of the element as a ruby Time object.

See to_s



150
151
152
153
154
# File 'lib/handsoap/xml_query_front.rb', line 150

def to_date
  t = self.to_s
  return if t.nil?
  Time.iso8601(t)
end

#to_fObject

Returns the value of the element as a float.

See to_s



134
135
136
137
138
# File 'lib/handsoap/xml_query_front.rb', line 134

def to_f
  t = self.to_s
  return if t.nil?
  t.to_f
end

#to_iObject

Returns the value of the element as an integer.

See to_s



126
127
128
129
130
# File 'lib/handsoap/xml_query_front.rb', line 126

def to_i
  t = self.to_s
  return if t.nil?
  t.to_i
end

#to_rawObject

Returns the outer XML for this element, preserving the original formatting.

Raises:

  • (NotImplementedError)


186
187
188
# File 'lib/handsoap/xml_query_front.rb', line 186

def to_raw
  raise NotImplementedError.new
end

#to_sObject

Returns the inner text content of this element, or the value (if it’s an attr or textnode).

The output is a UTF-8 encoded string, without xml-entities.

Raises:

  • (NotImplementedError)


158
159
160
# File 'lib/handsoap/xml_query_front.rb', line 158

def to_s
  raise NotImplementedError.new
end

#to_xmlObject

Returns the outer XML for this element.

Raises:

  • (NotImplementedError)


182
183
184
# File 'lib/handsoap/xml_query_front.rb', line 182

def to_xml
  raise NotImplementedError.new
end

#xpath(expression, ns = nil) ⇒ Object

Queries the document with XPath, relative to the current element.

ns Should be a Hash of prefix => namespace

Returns a NodeSelection

See add_namespace

Raises:

  • (NotImplementedError)


178
179
180
# File 'lib/handsoap/xml_query_front.rb', line 178

def xpath(expression, ns = nil)
  raise NotImplementedError.new
end