Parent

LibXML::XML::Node

Public Instance Methods

attribute?() click to toggle source

Specifies if this is an attribute node

# File lib/libxml/node.rb, line 206
def attribute?
  node_type == ATTRIBUTE_NODE
end
attribute_decl?() click to toggle source

Specifies if this is an attribute declaration node

# File lib/libxml/node.rb, line 211
def attribute_decl?
  node_type == ATTRIBUTE_DECL
end
attributes?() click to toggle source

Determines whether this node has attributes

# File lib/libxml/node.rb, line 8
def attributes?
  attributes.length > 0
end
cdata?() click to toggle source

Specifies if this is an CDATA node

# File lib/libxml/node.rb, line 216
def cdata?
  node_type == CDATA_SECTION_NODE
end
child?() click to toggle source
Alias for: first?
children() click to toggle source

Returns this node's children as an array.

# File lib/libxml/node.rb, line 130
def children
  entries
end
children?() click to toggle source
Alias for: first?
clone() click to toggle source

Create a shallow copy of the node. To create a deep copy call Node#copy(true)

# File lib/libxml/node.rb, line 14
def clone
  copy(false)
end
comment?() click to toggle source

Specifies if this is an comment node

# File lib/libxml/node.rb, line 221
def comment?
  node_type == COMMENT_NODE
end
context(namespaces=nil) → XPath::Context click to toggle source

Returns a new XML::XPathContext for the current node.

Namespaces is an optional array of XML::NS objects

# File lib/libxml/node.rb, line 52
def context(nslist = nil)
  if not self.doc
    raise(TypeError, "A node must belong to a document before a xpath context can be created")
  end

  context = XPath::Context.new(self.doc)
  context.node = self
  context.register_namespaces_from_node(self)
  context.register_namespaces_from_node(self.doc.root)
  context.register_namespaces(nslist) if nslist
  context
end
docbook_doc?() click to toggle source

Specifies if this is an docbook node

# File lib/libxml/node.rb, line 226
def docbook_doc?
  node_type == DOCB_DOCUMENT_NODE
end
doctype?() click to toggle source

Specifies if this is an doctype node

# File lib/libxml/node.rb, line 231
def doctype?
  node_type == DOCUMENT_TYPE_NODE
end
document?() click to toggle source

Specifies if this is an document node

# File lib/libxml/node.rb, line 236
def document?
  node_type == DOCUMENT_NODE
end
dtd?() click to toggle source

Specifies if this is an DTD node

# File lib/libxml/node.rb, line 241
def dtd?
  node_type == DTD_NODE
end
dup → XML::Node click to toggle source

Create a shallow copy of the node. To create a deep copy call Node#copy(true)

# File lib/libxml/node.rb, line 42
def dup
  copy(false)
end
each_attr() click to toggle source

------- Traversal ---------------- Iterates over this node's attributes.

doc = XML::Document.new('model/books.xml')
doc.root.each_attr {|attr| puts attr}
# File lib/libxml/node.rb, line 102
def each_attr
  attributes.each do |attr|
    yield(attr)
  end
end
each_element() click to toggle source

Iterates over this node's child elements (nodes that have a node_type == ELEMENT_NODE).

doc = XML::Document.new('model/books.xml')
doc.root.each_element {|element| puts element}
# File lib/libxml/node.rb, line 113
def each_element
  each do |node|
    yield(node) if node.node_type == ELEMENT_NODE
  end
end
element?() click to toggle source

Specifies if this is an element node

# File lib/libxml/node.rb, line 246
def element?
  node_type == ELEMENT_NODE
end
element_decl?() click to toggle source

Specifies if this is an element declaration node

# File lib/libxml/node.rb, line 256
def element_decl?
  node_type == ELEMENT_DECL
end
entity?() click to toggle source

Specifies if this is an entity node

# File lib/libxml/node.rb, line 251
def entity?
  node_type == ENTITY_NODE
end
entity_ref?() click to toggle source

Specifies if this is an entity reference node

# File lib/libxml/node.rb, line 261
def entity_ref?
  node_type == ENTITY_REF_NODE
end
find(namespaces=nil) → XPath::XPathObject click to toggle source

Return nodes matching the specified xpath expression. For more information, please refer to the documentation for XML::Document#find.

Namespaces is an optional array of XML::NS objects

# File lib/libxml/node.rb, line 73
def find(xpath, nslist = nil)
  self.context(nslist).find(xpath)
end
find_first(namespaces=nil) → XML::Node click to toggle source

Return the first node matching the specified xpath expression. For more information, please refer to the documentation for the find method.

# File lib/libxml/node.rb, line 83
def find_first(xpath, nslist = nil)
  find(xpath, nslist).first
end
first?() click to toggle source

Determines whether this node has a first node

# File lib/libxml/node.rb, line 125
def first?
  not first.nil?
end
Also aliased as: child?, children?
fragment?() click to toggle source

Specifies if this is a fragment node

# File lib/libxml/node.rb, line 266
def fragment?
  node_type == DOCUMENT_FRAG_NODE
end
html_doc?() click to toggle source

Specifies if this is a html document node

# File lib/libxml/node.rb, line 271
def html_doc?
  node_type == HTML_DOCUMENT_NODE
end
inner_xml → "string" click to toggle source
inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) → "string"

Converts a node's children, to a string representation. To include the node, use XML::Node#to_s. For more information about the supported options, see XML::Node#to_s.

# File lib/libxml/node.rb, line 25
def inner_xml(options = Hash.new)
  io = nil
  self.each do |node|
    xml = node.to_s(options)
    # Create the string IO here since we now know the encoding

    io = create_string_io(xml) unless io
    io << xml
  end

  io ? io.string : nil
end
last?() click to toggle source

Determines whether this node has a last node

# File lib/libxml/node.rb, line 145
def last?
  not last.nil?
end
namespace?() click to toggle source

Specifies if this is a namespace node (not if it has a namepsace)

# File lib/libxml/node.rb, line 277
def namespace?
  node_type == NAMESPACE_DECL
end
namespacess → XML::Namespaces click to toggle source

Returns this node's XML::Namespaces object, which is used to access the namespaces associated with this node.

# File lib/libxml/node.rb, line 93
def namespaces
  @namespaces ||= XML::Namespaces.new(self)
end
next?() click to toggle source

Determines whether this node has a next node

# File lib/libxml/node.rb, line 135
def next?
  not self.next.nil?
end
node_type_name() click to toggle source

Returns this node's type name

# File lib/libxml/node.rb, line 153
def node_type_name
  case node_type
    # Most common choices first

    when ATTRIBUTE_NODE
      'attribute'
    when DOCUMENT_NODE
      'document_xml'
    when ELEMENT_NODE
      'element'
    when TEXT_NODE
      'text'
    
    # Now the rest  

    when ATTRIBUTE_DECL
      'attribute_decl'
    when CDATA_SECTION_NODE
      'cdata'
    when COMMENT_NODE
      'comment'
    when DOCB_DOCUMENT_NODE
      'document_docbook'
    when DOCUMENT_FRAG_NODE
      'fragment'
    when DOCUMENT_TYPE_NODE
      'doctype'
    when DTD_NODE
      'dtd'
    when ELEMENT_DECL
      'elem_decl'
    when ENTITY_DECL
      'entity_decl'
    when ENTITY_NODE
      'entity'
    when ENTITY_REF_NODE
      'entity_ref'
    when HTML_DOCUMENT_NODE
      'document_html'
    when NAMESPACE_DECL
      'namespace'
    when NOTATION_NODE
      'notation'
    when PI_NODE
      'pi'
    when XINCLUDE_START
      'xinclude_start'
    when XINCLUDE_END
      'xinclude_end'
    else
      raise(UnknownType, "Unknown node type: %n", node.node_type);
  end
end
notation?() click to toggle source

Specifies if this is a notation node

# File lib/libxml/node.rb, line 282
def notation?
  node_type == NOTATION_NODE
end
parent?() click to toggle source

Determines whether this node has a parent node

# File lib/libxml/node.rb, line 120
def parent?
  not parent.nil?
end
pi?() click to toggle source

Specifies if this is a processiong instruction node

# File lib/libxml/node.rb, line 287
def pi?
  node_type == PI_NODE
end
prev?() click to toggle source

Determines whether this node has a previous node

# File lib/libxml/node.rb, line 140
def prev?
  not prev.nil?
end
properties() click to toggle source
# File lib/libxml/properties.rb, line 10
def properties
  warn('Node#properties is deprecated.  Use Node#attributes instead.')
  self.attributes
end
properties?() click to toggle source
# File lib/libxml/properties.rb, line 15
def properties?
  warn('Node#properties? is deprecated.  Use Node#attributes? instead.')
  self.attributes?
end
property(name) click to toggle source
# File lib/libxml/properties.rb, line 5
def property(name)
  warn('Node#properties is deprecated.  Use Node#[] instead.')
  self[name]
end
text?() click to toggle source

Specifies if this is a text node

# File lib/libxml/node.rb, line 292
def text?
  node_type == TEXT_NODE
end
xinclude_end?() click to toggle source

Specifies if this is an xinclude end node

# File lib/libxml/node.rb, line 297
def xinclude_end?
  node_type == XINCLUDE_END
end
xinclude_start?() click to toggle source

Specifies if this is an xinclude start node

# File lib/libxml/node.rb, line 302
def xinclude_start?
  node_type == XINCLUDE_START
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.