Class | Nokogiri::XML::Node |
In: |
lib/nokogiri/xml/node.rb
lib/nokogiri/xml/node/save_options.rb ext/nokogiri/xml_comment.c |
Parent: | Object |
call-seq:
type
The type for this document
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 |
next_sibling | -> | next |
previous_sibling | -> | previous |
unlink | -> | remove |
set_attribute | -> | : |
content | -> | text |
content | -> | inner_text |
key? | -> | has_attribute? |
add_child | -> | << |
node_name | -> | name |
node_name= | -> | name= |
node_type | -> | type |
text | -> | to_str |
Create a new node from string
THIS METHOD IS DEPRECATED This method is deprecated and will be removed in 1.3.0 or by March 1, 2009. Instead, use Nokogiri::XML::Node#fragment()
Returns a hash containing the node‘s attributes. The key is the attribute name, the value is the string value of the attribute.
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 })
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.
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.
Serialize Node using encoding and save_options. Save options can also be set using a block. See SaveOptions.
These two statements are equivalent:
node.serialize('UTF-8', FORMAT | AS_XML)
or
node.serialize('UTF-8') do |config| config.format.as_xml end
Write Node to io with encoding and save_options
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 }.new)