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

- (Object) /(expression)

alias of xpath



217
218
219
# File 'lib/handsoap/xml_query_front.rb', line 217

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

- (Object) [](attribute_name)

Returns the attribute value of the underlying element.

Shortcut for:

(node/"@attribute_name").to_s

Raises:

  • (NotImplementedError)


225
226
227
# File 'lib/handsoap/xml_query_front.rb', line 225

def [](attribute_name)
  raise NotImplementedError.new
end

- (Object) add_namespace(prefix, uri)

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.



124
125
126
# File 'lib/handsoap/xml_query_front.rb', line 124

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

- (Object) assert_prefixes!(expression, ns)

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



128
129
130
131
132
# File 'lib/handsoap/xml_query_front.rb', line 128

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

- (Object) children

Returns a NodeSelection

Raises:

  • (NotImplementedError)


205
206
207
# File 'lib/handsoap/xml_query_front.rb', line 205

def children
  raise NotImplementedError.new
end

- (Object) initialize(element, namespaces = {})



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

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

- (Object) native_element

Returns the underlying native element.

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



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

def native_element
  @element
end

- (Object) node_name

Returns the node name of the current element.

Raises:

  • (NotImplementedError)


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

def node_name
  raise NotImplementedError.new
end

- (Object) node_namespace

Returns the node namespace uri of the current element if any, nil otherwise. Result returned for attribute nodes varies for different drivers, currently.

Raises:

  • (NotImplementedError)


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

def node_namespace
  raise NotImplementedError.new
end

- (Object) to_big_decimal(decimal_places = 2)

Returns the value of the element as an instance of BigDecimal

See to_s



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

def to_big_decimal(decimal_places = 2)
  t = self.to_s
  return if t.nil?
  BigDecimal.new t, decimal_places
end

- (Object) to_boolean

Returns the value of the element as an boolean.

See to_s



152
153
154
155
156
# File 'lib/handsoap/xml_query_front.rb', line 152

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

- (Object) to_date

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

See to_s



160
161
162
163
164
# File 'lib/handsoap/xml_query_front.rb', line 160

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

- (Object) to_f

Returns the value of the element as a float.

See to_s



144
145
146
147
148
# File 'lib/handsoap/xml_query_front.rb', line 144

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

- (Object) to_i

Returns the value of the element as an integer.

See to_s



136
137
138
139
140
# File 'lib/handsoap/xml_query_front.rb', line 136

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

- (Object) to_raw

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

Raises:

  • (NotImplementedError)


213
214
215
# File 'lib/handsoap/xml_query_front.rb', line 213

def to_raw
  raise NotImplementedError.new
end

- (Object) to_s

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)


176
177
178
# File 'lib/handsoap/xml_query_front.rb', line 176

def to_s
  raise NotImplementedError.new
end

- (Object) to_xml

Returns the outer XML for this element.

Raises:

  • (NotImplementedError)


209
210
211
# File 'lib/handsoap/xml_query_front.rb', line 209

def to_xml
  raise NotImplementedError.new
end

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

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)


201
202
203
# File 'lib/handsoap/xml_query_front.rb', line 201

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