Class Nokogiri::XML::Node
In: lib/nokogiri/xml/node.rb
ext/nokogiri/html_document.c
Parent: Object

Methods

Constants

ELEMENT_NODE = 1
ATTRIBUTE_NODE = 2
TEXT_NODE = 3
CDATA_SECTION_NODE = 4
ENTITY_REF_NODE = 5
ENTITY_NODE = 6
PI_NODE = 7
COMMENT_NODE = 8
DOCUMENT_NODE = 9
DOCUMENT_TYPE_NODE = 10
DOCUMENT_FRAG_NODE = 11
NOTATION_NODE = 12
HTML_DOCUMENT_NODE = 13
DTD_NODE = 14
ELEMENT_DECL = 15
ATTRIBUTE_DECL = 16
ENTITY_DECL = 17
NAMESPACE_DECL = 18
XINCLUDE_START = 19
XINCLUDE_END = 20
DOCB_DOCUMENT_NODE = 21

Attributes

document  [RW] 

Public Class methods

Create a new node with name

Create a new node by parsing string

Public Instance methods

/(*paths)

Alias for search

Set the property to value

Add node as a child of this node. Returns the new child node.

Insert node after this node (as a sibling).

Insert node before this node (as a sibling).

Create nodes from data and insert them after this node (as a sibling).

Get a list of ancestor Node for this Node

returns a list containing the Node attributes.

Returns a hash containing the node‘s attributes. The key is the attribute name, the value is the string value of the attribute.

Create nodes from data and insert them before this node (as a sibling).

Is this node blank?

Returns the child node

Get the list of children for this node as a NodeSet

recursively get all namespaces from this node and its subtree

Returns the content for this Node

Set the content to string. If encode, encode any special characters first.

Search this node for CSS rules. rules must be one or more CSS selectors. For example:

  node.css('title')
  node.css('body h1.bold')
  node.css('div + p.green', 'div#one')

Custom CSS pseudo classes may also be defined. To define custom pseudo classes, create a class and implement the custom pseudo class you want defined. The first argument to the method will be the current matching NodeSet. Any other arguments are ones that you pass in. For example:

  node.css('title:regex("\w+")', Class.new {
    def regex node_set, regex
      node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
    end
  })

Decorate this node with the decorators set up in this node‘s Document

delete(name)

Alias for remove_attribute

Copy this node. An optional depth may be passed in, but it defaults to a deep copy. 0 is a shallow copy, 1 is a deep copy.

elem?()

Alias for element?

Encode any special characters in string

Get the value for attribute

get_attribute(property)

Alias for #[]

inner_text()

Alias for text

Get the internal subset

Returns true if attribute is set

Returns the name for this Node

Set the name for this Node

returns the namespace prefix for the node, if one exists.

returns a hash containing the node‘s namespaces.

Set the content for this Node

Returns the next sibling node

Get the parent Node for this Node

Returns the path associated with this Node

Get the internal pointer number

Returns the previous sibling node

Remove the attribute named name

replace node with the new node in the document.

Search this node for paths. paths can be XPath or CSS, and an optional hash of namespaces may be appended. See Node#xpath and Node#css.

Returns this node as HTML

Returns this node as XML

Yields self and all children to block recursively.

Get the type for this node

Unlink this node from its current context.

Search this node for XPath paths. paths must be one or more XPath queries. A hash of namespaces may be appended. For example:

  node.xpath('.//title')
  node.xpath('.//foo:name', { 'foo' => 'http://example.org/' })
  node.xpath('.//xmlns:name', node.root.namespaces)

Custom XPath functions may also be defined. To define custom functions create a class and implement the # function you want to define. For example:

  node.xpath('.//title[regex(., "\w+")]', Class.new {
    def regex node_set, regex
      node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
    end
  })

[Validate]