Object
Specifies if this is an attribute node
# File lib/libxml/node.rb, line 207 207: def attribute? 208: node_type == ATTRIBUTE_NODE 209: end
Specifies if this is an attribute declaration node
# File lib/libxml/node.rb, line 212 212: def attribute_decl? 213: node_type == ATTRIBUTE_DECL 214: end
Determines whether this node has attributes
# File lib/libxml/node.rb, line 9 9: def attributes? 10: attributes.length > 0 11: end
Specifies if this is an CDATA node
# File lib/libxml/node.rb, line 217 217: def cdata? 218: node_type == CDATA_SECTION_NODE 219: end
Returns this node’s children as an array.
# File lib/libxml/node.rb, line 131 131: def children 132: entries 133: end
Create a shallow copy of the node. To create a deep copy call Node#copy(true)
# File lib/libxml/node.rb, line 15 15: def clone 16: copy(false) 17: 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 53 53: def context(nslist = nil) 54: if not self.doc 55: raise(TypeError, "A node must belong to a document before a xpath context can be created") 56: end 57: 58: context = XPath::Context.new(self.doc) 59: context.node = self 60: context.register_namespaces_from_node(self) 61: context.register_namespaces_from_node(self.doc.root) 62: context.register_namespaces(nslist) if nslist 63: context 64: end
Specifies if this is an docbook node
# File lib/libxml/node.rb, line 227 227: def docbook_doc? 228: node_type == DOCB_DOCUMENT_NODE 229: end
Specifies if this is an doctype node
# File lib/libxml/node.rb, line 232 232: def doctype? 233: node_type == DOCUMENT_TYPE_NODE 234: end
Specifies if this is an document node
# File lib/libxml/node.rb, line 237 237: def document? 238: node_type == DOCUMENT_NODE 239: end
Specifies if this is an DTD node
# File lib/libxml/node.rb, line 242 242: def dtd? 243: node_type == DTD_NODE 244: end
Create a shallow copy of the node. To create a deep copy call Node#copy(true)
# File lib/libxml/node.rb, line 43 43: def dup 44: copy(false) 45: 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 103 103: def each_attr 104: attributes.each do |attr| 105: yield(attr) 106: end 107: 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 114 114: def each_element 115: each do |node| 116: yield(node) if node.node_type == ELEMENT_NODE 117: end 118: end
Specifies if this is an element node
# File lib/libxml/node.rb, line 247 247: def element? 248: node_type == ELEMENT_NODE 249: end
Specifies if this is an element declaration node
# File lib/libxml/node.rb, line 257 257: def element_decl? 258: node_type == ELEMENT_DECL 259: end
Specifies if this is an entity node
# File lib/libxml/node.rb, line 252 252: def entity? 253: node_type == ENTITY_NODE 254: end
Specifies if this is an entity reference node
# File lib/libxml/node.rb, line 262 262: def entity_ref? 263: node_type == ENTITY_REF_NODE 264: end
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 74 74: def find(xpath, nslist = nil) 75: self.context(nslist).find(xpath) 76: end
Return the first node matching the specified xpath expression. For more information, please refer to the documentation for the # method.
# File lib/libxml/node.rb, line 84 84: def find_first(xpath, nslist = nil) 85: find(xpath, nslist).first 86: end
Determines whether this node has a first node
# File lib/libxml/node.rb, line 126 126: def first? 127: not first.nil? 128: end
Specifies if this is a fragment node
# File lib/libxml/node.rb, line 267 267: def fragment? 268: node_type == DOCUMENT_FRAG_NODE 269: end
Specifies if this is a html document node
# File lib/libxml/node.rb, line 272 272: def html_doc? 273: node_type == HTML_DOCUMENT_NODE 274: 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 26 26: def inner_xml(options = Hash.new) 27: io = nil 28: self.each do |node| 29: xml = node.to_s(options) 30: # Create the string IO here since we now know the encoding 31: io = create_string_io(xml) unless io 32: io << xml 33: end 34: 35: io ? io.string : nil 36: end
Determines whether this node has a last node
# File lib/libxml/node.rb, line 146 146: def last? 147: not last.nil? 148: end
Specifies if this is a namespace node (not if it has a namepsace)
# File lib/libxml/node.rb, line 278 278: def namespace? 279: node_type == NAMESPACE_DECL 280: 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 94 94: def namespaces 95: @namespaces ||= XML::Namespaces.new(self) 96: end
Determines whether this node has a next node
# File lib/libxml/node.rb, line 136 136: def next? 137: not self.next.nil? 138: end
Returns this node’s type name
# File lib/libxml/node.rb, line 154 154: def node_type_name 155: case node_type 156: # Most common choices first 157: when ATTRIBUTE_NODE 158: 'attribute' 159: when DOCUMENT_NODE 160: 'document_xml' 161: when ELEMENT_NODE 162: 'element' 163: when TEXT_NODE 164: 'text' 165: 166: # Now the rest 167: when ATTRIBUTE_DECL 168: 'attribute_decl' 169: when CDATA_SECTION_NODE 170: 'cdata' 171: when COMMENT_NODE 172: 'comment' 173: when DOCB_DOCUMENT_NODE 174: 'document_docbook' 175: when DOCUMENT_FRAG_NODE 176: 'fragment' 177: when DOCUMENT_TYPE_NODE 178: 'doctype' 179: when DTD_NODE 180: 'dtd' 181: when ELEMENT_DECL 182: 'elem_decl' 183: when ENTITY_DECL 184: 'entity_decl' 185: when ENTITY_NODE 186: 'entity' 187: when ENTITY_REF_NODE 188: 'entity_ref' 189: when HTML_DOCUMENT_NODE 190: 'document_html' 191: when NAMESPACE_DECL 192: 'namespace' 193: when NOTATION_NODE 194: 'notation' 195: when PI_NODE 196: 'pi' 197: when XINCLUDE_START 198: 'xinclude_start' 199: when XINCLUDE_END 200: 'xinclude_end' 201: else 202: raise(UnknownType, "Unknown node type: %n", node.node_type); 203: end 204: end
Specifies if this is a notation node
# File lib/libxml/node.rb, line 283 283: def notation? 284: node_type == NOTATION_NODE 285: end
Determines whether this node has a parent node
# File lib/libxml/node.rb, line 121 121: def parent? 122: not parent.nil? 123: end
Specifies if this is a processiong instruction node
# File lib/libxml/node.rb, line 288 288: def pi? 289: node_type == PI_NODE 290: end
Determines whether this node has a previous node
# File lib/libxml/node.rb, line 141 141: def prev? 142: not prev.nil? 143: end
# File lib/libxml/properties.rb, line 11 11: def properties 12: warn('Node#properties is deprecated. Use Node#attributes instead.') 13: self.attributes 14: end
# File lib/libxml/properties.rb, line 16 16: def properties? 17: warn('Node#properties? is deprecated. Use Node#attributes? instead.') 18: self.attributes? 19: end
# File lib/libxml/properties.rb, line 6 6: def property(name) 7: warn('Node#properties is deprecated. Use Node#[] instead.') 8: self[name] 9: end
Specifies if this is a text node
# File lib/libxml/node.rb, line 293 293: def text? 294: node_type == TEXT_NODE 295: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.
Specifies if this is an comment node