Class: Nokogiri::XML::Namespace

Inherits:
Object
  • Object
show all
Includes:
PP::Node
Defined in:
lib/nokogiri/xml/namespace.rb,
lib/nokogiri/ffi/xml/namespace.rb,
ext/nokogiri/xml_namespace.c

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PP::Node

#inspect, #pretty_print

Instance Attribute Details

#cstructObject

:stopdoc:



6
7
8
# File 'lib/nokogiri/ffi/xml/namespace.rb', line 6

def cstruct
  @cstruct
end

#documentObject

Returns the value of attribute document.



5
6
7
# File 'lib/nokogiri/xml/namespace.rb', line 5

def document
  @document
end

Class Method Details

.wrap(document, node_struct) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nokogiri/ffi/xml/namespace.rb', line 18

def wrap(document, node_struct)
  if node_struct.is_a?(FFI::Pointer)
    # cast native pointers up into a node cstruct
    return nil if node_struct.null?
    node_struct = LibXML::XmlNs.new(node_struct) 
  end

  ruby_node = node_struct.ruby_node
  return ruby_node unless ruby_node.nil?

  ns = Nokogiri::XML::Namespace.allocate
  ns.document = document.ruby_doc
  ns.cstruct = node_struct

  ns.cstruct.ruby_node = ns

  cache = ns.document.instance_variable_get(:@node_cache)
  cache << ns

  ns
end

Instance Method Details

#hrefObject

Get the href for this namespace



30
31
32
# File 'ext/nokogiri/xml_namespace.c', line 30

def href
  cstruct[:href].nil? ? nil : cstruct[:href] # TODO: encoding?
end

#prefixObject

Get the prefix for this namespace. Returns nil if there is no prefix.



11
12
13
# File 'ext/nokogiri/xml_namespace.c', line 11

def prefix
  cstruct[:prefix].nil? ? nil : cstruct[:prefix] # TODO: encoding?
end