Specifies if this is an attribute node
# File lib/libxml/node.rb, line 206 def attribute? node_type == ATTRIBUTE_NODE end
Specifies if this is an attribute declaration node
# File lib/libxml/node.rb, line 211 def attribute_decl? node_type == ATTRIBUTE_DECL end
Determines whether this node has attributes
# File lib/libxml/node.rb, line 8 def attributes? attributes.length > 0 end
Specifies if this is an CDATA node
# File lib/libxml/node.rb, line 216 def cdata? node_type == CDATA_SECTION_NODE end
Returns this node’s children as an array.
# File lib/libxml/node.rb, line 130 def children entries end
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
Specifies if this is an comment node
# File lib/libxml/node.rb, line 221 def comment? node_type == COMMENT_NODE end
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
Specifies if this is an docbook node
# File lib/libxml/node.rb, line 226 def docbook_doc? node_type == DOCB_DOCUMENT_NODE end
Specifies if this is an doctype node
# File lib/libxml/node.rb, line 231 def doctype? node_type == DOCUMENT_TYPE_NODE end
Specifies if this is an document node
# File lib/libxml/node.rb, line 236 def document? node_type == DOCUMENT_NODE end
Specifies if this is an DTD node
# File lib/libxml/node.rb, line 241 def dtd? node_type == DTD_NODE end
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
——- 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
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
Specifies if this is an element node
# File lib/libxml/node.rb, line 246 def element? node_type == ELEMENT_NODE end
Specifies if this is an element declaration node
# File lib/libxml/node.rb, line 256 def element_decl? node_type == ELEMENT_DECL end
Specifies if this is an entity node
# File lib/libxml/node.rb, line 251 def entity? node_type == ENTITY_NODE end
Specifies if this is an entity reference node
# File lib/libxml/node.rb, line 261 def entity_ref? node_type == ENTITY_REF_NODE end
Return nodes matching the specified xpath expression. For more information, please refer to the documentation for LibXML::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
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
Determines whether this node has a first node
# File lib/libxml/node.rb, line 125 def first? not first.nil? end
Specifies if this is a fragment node
# File lib/libxml/node.rb, line 266 def fragment? node_type == DOCUMENT_FRAG_NODE end
Specifies if this is a html document node
# File lib/libxml/node.rb, line 271 def html_doc? node_type == HTML_DOCUMENT_NODE end
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
Determines whether this node has a last node
# File lib/libxml/node.rb, line 145 def last? not last.nil? end
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
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
Determines whether this node has a next node
# File lib/libxml/node.rb, line 135 def next? not self.next.nil? end
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
Specifies if this is a notation node
# File lib/libxml/node.rb, line 282 def notation? node_type == NOTATION_NODE end
Determines whether this node has a parent node
# File lib/libxml/node.rb, line 120 def parent? not parent.nil? end
Specifies if this is a processiong instruction node
# File lib/libxml/node.rb, line 287 def pi? node_type == PI_NODE end
Determines whether this node has a previous node
# File lib/libxml/node.rb, line 140 def prev? not prev.nil? end
# File lib/libxml/properties.rb, line 10 def properties warn('Node#properties is deprecated. Use Node#attributes instead.') self.attributes end
# File lib/libxml/properties.rb, line 15 def properties? warn('Node#properties? is deprecated. Use Node#attributes? instead.') self.attributes? end
# File lib/libxml/properties.rb, line 5 def property(name) warn('Node#properties is deprecated. Use Node#[] instead.') self[name] end
Specifies if this is a text node
# File lib/libxml/node.rb, line 292 def text? node_type == TEXT_NODE end
Specifies if this is an xinclude end node
# File lib/libxml/node.rb, line 297 def xinclude_end? node_type == XINCLUDE_END end
Specifies if this is an xinclude start node
# File lib/libxml/node.rb, line 302 def xinclude_start? node_type == XINCLUDE_START end