Class | LibXML::XML::Node |
In: |
ext/libxml/libxml.c
lib/libxml/node.rb lib/libxml/node_set.rb lib/libxml/properties.rb |
Parent: | Object |
SPACE_DEFAULT | = | INT2NUM(0) |
SPACE_PRESERVE | = | INT2NUM(1) |
SPACE_NOT_INHERIT | = | INT2NUM(-1) |
XLINK_ACTUATE_AUTO | = | INT2NUM(1) |
XLINK_ACTUATE_NONE | = | INT2NUM(0) |
XLINK_ACTUATE_ONREQUEST | = | INT2NUM(2) |
XLINK_SHOW_EMBED | = | INT2NUM(2) |
XLINK_SHOW_NEW | = | INT2NUM(1) |
XLINK_SHOW_NONE | = | INT2NUM(0) |
XLINK_SHOW_REPLACE | = | INT2NUM(3) |
XLINK_TYPE_EXTENDED | = | INT2NUM(2) |
XLINK_TYPE_EXTENDED_SET | = | INT2NUM(3) |
XLINK_TYPE_NONE | = | INT2NUM(0) |
XLINK_TYPE_SIMPLE | = | INT2NUM(1) |
ELEMENT_NODE | = | INT2FIX(XML_ELEMENT_NODE) |
ATTRIBUTE_NODE | = | INT2FIX(XML_ATTRIBUTE_NODE) |
TEXT_NODE | = | INT2FIX(XML_TEXT_NODE) |
CDATA_SECTION_NODE | = | INT2FIX(XML_CDATA_SECTION_NODE) |
ENTITY_REF_NODE | = | INT2FIX(XML_ENTITY_REF_NODE) |
ENTITY_NODE | = | INT2FIX(XML_ENTITY_NODE) |
PI_NODE | = | INT2FIX(XML_PI_NODE) |
COMMENT_NODE | = | INT2FIX(XML_COMMENT_NODE) |
DOCUMENT_NODE | = | INT2FIX(XML_DOCUMENT_NODE) |
DOCUMENT_TYPE_NODE | = | INT2FIX(XML_DOCUMENT_TYPE_NODE) |
DOCUMENT_FRAG_NODE | = | INT2FIX(XML_DOCUMENT_FRAG_NODE) |
NOTATION_NODE | = | INT2FIX(XML_NOTATION_NODE) |
HTML_DOCUMENT_NODE | = | INT2FIX(XML_HTML_DOCUMENT_NODE) |
DTD_NODE | = | INT2FIX(XML_DTD_NODE) |
ELEMENT_DECL | = | INT2FIX(XML_ELEMENT_DECL) |
ATTRIBUTE_DECL | = | INT2FIX(XML_ATTRIBUTE_DECL) |
ENTITY_DECL | = | INT2FIX(XML_ENTITY_DECL) |
NAMESPACE_DECL | = | INT2FIX(XML_NAMESPACE_DECL) |
XINCLUDE_START | = | INT2FIX(XML_XINCLUDE_START) |
XINCLUDE_END | = | INT2FIX(XML_XINCLUDE_END) |
DOCB_DOCUMENT_NODE | = | INT2FIX(XML_DOCB_DOCUMENT_NODE) |
DOCB_DOCUMENT_NODE | = | Qnil |
Create a new element node with the specified name, optionally setting the node’s content. backward compatibility for <.5 new
/* * call-seq: * XML::Node.new(name, content = nil) -> XML::Node * XML::Node.new_element(name, content = nil) -> XML::Node * * Create a new element node with the specified name, optionally setting * the node's content. * backward compatibility for <.5 new */ VALUE ruby_xml_node2_new_string_bc(int argc, VALUE *argv, VALUE class) { VALUE content=Qnil; VALUE name=Qnil; switch(argc) { case 2: content=argv[1]; if ( TYPE(content) != T_STRING) content=rb_obj_as_string(content); case 1: name=check_string_or_symbol( argv[0] ); return ruby_xml_node2_new_string(class,Qnil,name,content); default: rb_raise(rb_eArgError, "wrong number of arguments (1 or 2) given %d",argc); } }
Create a new CDATA node, optionally setting the node’s content.
/* * call-seq: * XML::Node.new_cdata(content = nil) -> XML::Node * * Create a new #CDATA node, optionally setting * the node's content. */ VALUE ruby_xml_node_new_cdata(int argc, VALUE *argv, VALUE class) {
Create a new comment node, optionally setting the node’s content.
/* * call-seq: * XML::Node.new_comment(content = nil) -> XML::Node * * Create a new comment node, optionally setting * the node's content. * */ VALUE ruby_xml_node_new_comment(int argc, VALUE *argv, VALUE class) {
Create a new text node, optionally setting the node’s content.
/* * call-seq: * XML::Node.new_text(content = nil) -> XML::Node * * Create a new text node, optionally setting * the node's content. * */ VALUE ruby_xml_node_new_text(VALUE class, VALUE text) { VALUE obj; xmlNodePtr xnode; if ( NIL_P(text) ) return Qnil; if (TYPE(text) != T_STRING ) rb_raise(rb_eTypeError, "requires string argument"); xnode=xmlNewText((xmlChar*)STR2CSTR(text)); if ( xnode == NULL ) return Qnil; obj=ruby_xml_node2_wrap(class,xnode); rb_obj_call_init(obj,0,NULL); return obj; }
Obtain the named property.
/* * call-seq: * node.property("name") -> "string" * node["name"] -> "string" * * Obtain the named property. */ VALUE ruby_xml_node_property_get(VALUE self, VALUE name) {
Specifies if this is an attribute node
# File lib/libxml/node.rb, line 158 158: def attribute? 159: node_type == ATTRIBUTE_NODE 160: end
Specifies if this is an attribute declaration node
# File lib/libxml/node.rb, line 163 163: def attribute_decl? 164: node_type == ATTRIBUTE_DECL 165: end
Returns the XML::Attributes for this node.
/* * call-seq: * node.attributes -> attributes * * Returns the XML::Attributes for this node. */ VALUE ruby_xml_node_attributes_get(VALUE self) {
Determines whether this node has attributes
# File lib/libxml/node.rb, line 8 8: def attributes? 9: attributes.length > 0 10: end
Obtain this node’s base URI.
/* * call-seq: * node.base -> "uri" * * Obtain this node's base URI. */ VALUE ruby_xml_node_base_get(VALUE self) {
Determine whether this node is empty.
/* * call-seq: * node.empty? -> (true|false) * * Determine whether this node is empty. */ VALUE ruby_xml_node_empty_q(VALUE self) {
Specifies if this is an CDATA node
# File lib/libxml/node.rb, line 168 168: def cdata? 169: node_type == CDATA_SECTION_NODE 170: end
Returns this node’s children as an array.
# File lib/libxml/node.rb, line 82 82: def children 83: entries 84: end
Specifies if this is an comment node
# File lib/libxml/node.rb, line 173 173: def comment? 174: node_type == COMMENT_NODE 175: end
Obtain this node’s content as a string.
/* * call-seq: * node.content -> "string" * * Obtain this node's content as a string. */ VALUE ruby_xml_node_content_get(VALUE self) {
Obtain this node’s stripped content.
Deprecated: Stripped content can be obtained via the content method.
/* * call-seq: * node.content_stripped -> "string" * * Obtain this node's stripped content. * * *Deprecated*: Stripped content can be obtained via the * +content+ method. */ VALUE ruby_xml_node_content_stripped_get(VALUE self) {
Creates a copy of this node. To create a shallow copy set the deep parameter to false. To create a deep copy set the deep parameter to true.
/* * call-seq: * node.copy -> XML::Node * * Creates a copy of this node. To create a * shallow copy set the deep parameter to false. * To create a deep copy set the deep parameter * to true. * */ VALUE ruby_xml_node_copy(VALUE self, VALUE deep) {
Dump this node to stdout, including any debugging information.
/* * call-seq: * node.debug_dump -> (true|nil) * * Dump this node to stdout, including any debugging * information. */ VALUE ruby_xml_node_debug_dump(VALUE self) {
Obtain the XML::Document this node belongs to.
/* * call-seq: * node.doc -> document * * Obtain the XML::Document this node belongs to. */ VALUE ruby_xml_node_doc(VALUE self) {
Specifies if this is an docbook node
# File lib/libxml/node.rb, line 178 178: def docbook_doc? 179: node_type == DOCB_DOCUMENT_NODE 180: end
Specifies if this is an docbook node
# File lib/libxml/node.rb, line 183 183: def doctype? 184: node_type == DOCUMENT_TYPE_NODE 185: end
Specifies if this is an DOCTYPE node
# File lib/libxml/node.rb, line 188 188: def document? 189: node_type == DOCUMENT_NODE 190: end
Specifies if this is an DTD node
# File lib/libxml/node.rb, line 193 193: def dtd? 194: node_type == DTD_NODE 195: end
Dump this node to stdout.
/* * call-seq: * node.dump -> (true|nil) * * Dump this node to stdout. */ VALUE ruby_xml_node_dump(VALUE self) {
Iterates over this node’s children, including text nodes, element nodes, etc. If you wish to iterate only over child elements, use XML::Node#each_element.
doc = XML::Document.new('model/books.xml') doc.root.each {|node| puts node}
/* * call-seq: * node.each -> XML::Node * * Iterates over this node's children, including text * nodes, element nodes, etc. If you wish to iterate * only over child elements, use XML::Node#each_element. * * doc = XML::Document.new('model/books.xml') * doc.root.each {|node| puts node} */ VALUE ruby_xml_node_each(VALUE self) {
——- 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 54 54: def each_attr 55: attributes.each do |attr| 56: yield(attr) 57: end 58: 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 65 65: def each_element 66: each do |node| 67: yield(node) if node.node_type == ELEMENT_NODE 68: end 69: end
Specifies if this is an element node
# File lib/libxml/node.rb, line 198 198: def element? 199: node_type == ELEMENT_NODE 200: end
Specifies if this is an element declaration node
# File lib/libxml/node.rb, line 208 208: def element_decl? 209: node_type == ELEMENT_DECL 210: end
Determine whether this node is empty.
/* * call-seq: * node.empty? -> (true|false) * * Determine whether this node is empty. */ VALUE ruby_xml_node_empty_q(VALUE self) {
Specifies if this is an entity node
# File lib/libxml/node.rb, line 203 203: def entity? 204: node_type == ENTITY_NODE 205: end
Specifies if this is an entity reference node
# File lib/libxml/node.rb, line 213 213: def entity_ref? 214: node_type == ENTITY_REF_NODE 215: end
Test equality between the two nodes. Two nodes are equal if they are the same node or have the same XML representation.
/* * call-seq: * node.eql?(other_node) => (true|false) * * Test equality between the two nodes. Two nodes are equal * if they are the same node or have the same XML representation.*/ VALUE ruby_xml_node_eql_q(VALUE self, VALUE other) {
Return nodes matching the specified xpath expression. For more information, please refer to the documentation for XML::Document#find.
# File lib/libxml/node.rb, line 27 27: def find(xpath, nslist = nil) 28: if not self.doc 29: raise(TypeError, "A node must belong to a document before " + 30: "it can be searched with XPath.") 31: end 32: 33: context = XPath::Context.new(self) 34: context.node = self 35: context.register_namespaces_from_node(self) 36: context.register_namespaces_from_node(self.doc.root) 37: context.register_namespaces(nslist) if nslist 38: 39: context.find(xpath) 40: end
Return the first node matching the specified xpath expression. For more information, please refer to the documentation for XML::Node#find.
# File lib/libxml/node.rb, line 45 45: def find_first(xpath, nslist = nil) 46: find(xpath, nslist).first 47: end
Returns this node’s first child node if any.
/* * call-seq: * node.first -> XML::Node * * Returns this node's first child node if any. */ VALUE ruby_xml_node_first_get(VALUE self) {
Determines whether this node has a first node
# File lib/libxml/node.rb, line 77 77: def first? 78: not first.nil? 79: end
Specifies if this is a fragment node
# File lib/libxml/node.rb, line 218 218: def fragment? 219: node_type == DOCUMENT_FRAG_NODE 220: end
Specifies if this is a html document node
# File lib/libxml/node.rb, line 223 223: def html_doc? 224: node_type == HTML_DOCUMENT_NODE 225: end
Obtain the last child node of this node, if any.
/* * call-seq: * node.last -> XML::Node * * Obtain the last child node of this node, if any. */ VALUE ruby_xml_node_last_get(VALUE self) {
Determines whether this node has a last node
# File lib/libxml/node.rb, line 97 97: def last? 98: not last.nil? 99: end
Obtain the line number (in the XML document) that this node was read from. If default_line_numbers is set false (the default), this method returns zero.
/* * call-seq: * node.line_num -> num * * Obtain the line number (in the XML document) that this * node was read from. If +default_line_numbers+ is set * false (the default), this method returns zero. */ VALUE ruby_xml_node_line_num(VALUE self) {
Obtain this node’s name.
/* * call-seq: * node.name -> "string" * * Obtain this node's name. */ VALUE ruby_xml_node_name_get(VALUE self) {
Specifies if this is a namespace node (not if it has a namepsace)
# File lib/libxml/node.rb, line 229 229: def namespace? 230: node_type == NAMESPACE_DECL 231: end
Obtain this node’s namespace node.
/* * call-seq: * node.namespace_node -> namespace. * * Obtain this node's namespace node. */ VALUE ruby_xml_node_namespace_get_node(VALUE self) {
Obtain the next sibling node, if any.
/* * call-seq: * node.next -> XML::Node * * Obtain the next sibling node, if any. */ VALUE ruby_xml_node_next_get(VALUE self) {
Insert the specified node as this node’s next sibling.
/* * call-seq: * node.next = node * * Insert the specified node as this node's next sibling. */ VALUE ruby_xml_node_next_set(VALUE self, VALUE rnode) {
Determines whether this node has a next node
# File lib/libxml/node.rb, line 87 87: def next? 88: not self.next.nil? 89: end
Obtain this node’s type identifier.
/* * call-seq: * node.type -> num * * Obtain this node's type identifier. */ VALUE ruby_xml_node_type(VALUE self) {
Returns this node’s type name
# File lib/libxml/node.rb, line 105 105: def node_type_name 106: case node_type 107: # Most common choices first 108: when ATTRIBUTE_NODE: 109: 'attribute' 110: when DOCUMENT_NODE: 111: 'document_xml' 112: when ELEMENT_NODE: 113: 'element' 114: when TEXT_NODE: 115: 'text' 116: 117: # Now the rest 118: when ATTRIBUTE_DECL: 119: 'attribute_decl' 120: when CDATA_SECTION_NODE: 121: 'cdata' 122: when COMMENT_NODE: 123: 'comment' 124: when DOCB_DOCUMENT_NODE: 125: 'document_docbook' 126: when DOCUMENT_FRAG_NODE: 127: 'fragment' 128: when DOCUMENT_TYPE_NODE: 129: 'doctype' 130: when DTD_NODE: 131: 'dtd' 132: when ELEMENT_DECL: 133: 'elem_decl' 134: when ENTITY_DECL: 135: 'entity_decl' 136: when ENTITY_NODE: 137: 'entity' 138: when ENTITY_REF_NODE: 139: 'entity_ref' 140: when HTML_DOCUMENT_NODE: 141: 'document_html' 142: when NAMESPACE_DECL: 143: 'namespace' 144: when NOTATION_NODE: 145: 'notation' 146: when PI_NODE: 147: 'pi' 148: when XINCLUDE_START: 149: 'xinclude_start' 150: when XINCLUDE_END: 151: 'xinclude_end' 152: else 153: raise(UnknownType, "Unknown node type: %n", node.node_type); 154: end 155: end
Specifies if this is a notation node
# File lib/libxml/node.rb, line 234 234: def notation? 235: node_type == NOTATION_NODE 236: end
Determine whether this node has a namespace.
/* * call-seq: * node.ns? -> (true|false) * * Determine whether this node has a namespace. */ VALUE ruby_xml_node_ns_q(VALUE self) {
Obtain this node’s default namespace.
/* * call-seq: * node.ns_def -> namespace * * Obtain this node's default namespace. */ VALUE ruby_xml_node_ns_def_get(VALUE self) {
Obtain this node’s parent node, if any.
/* * call-seq: * node.parent -> XML::Node * * Obtain this node's parent node, if any. */ VALUE ruby_xml_node_parent_get(VALUE self) {
Determines whether this node has a parent node
# File lib/libxml/node.rb, line 72 72: def parent? 73: not parent.nil? 74: end
Obtain this node’s path.
/* * call-seq: * node.path -> path * * Obtain this node's path. */ VALUE ruby_xml_node_path(VALUE self) {
Specifies if this is a processiong instruction node
# File lib/libxml/node.rb, line 239 239: def pi? 240: node_type == PI_NODE 241: end
Obtain the previous sibling, if any.
/* * call-seq: * node.prev -> XML::Node * * Obtain the previous sibling, if any. */ VALUE ruby_xml_node_prev_get(VALUE self) {
Insert the specified node as this node’s previous sibling.
/* * call-seq: * node.prev = node * * Insert the specified node as this node's previous sibling. */ VALUE ruby_xml_node_prev_set(VALUE self, VALUE rnode) {
Determines whether this node has a previous node
# File lib/libxml/node.rb, line 92 92: def prev? 93: not prev.nil? 94: end
Removes this node from it’s parent.
/* * call-seq: * node.remove! -> nil * * Removes this node from it's parent. */ VALUE ruby_xml_node_remove_ex(VALUE self) {
Search for a namespace by href.
/* * call-seq: * node.search_href -> namespace * * Search for a namespace by href. */ VALUE ruby_xml_node_search_href(VALUE self, VALUE href) {
Search for a namespace by namespace.
/* * call-seq: * node.search_ns -> namespace * * Search for a namespace by namespace. */ VALUE ruby_xml_node_search_ns(VALUE self, VALUE ns) {
Add the specified node as a sibling of this node.
/* * call-seq: * node.sibling(node) -> XML::Node * * Add the specified node as a sibling of this node. */ VALUE ruby_xml_node_sibling_set(VALUE self, VALUE rnode) {
Determine whether this node preserves whitespace.
/* * call-seq: * node.space_preserve -> (true|false) * * Determine whether this node preserves whitespace. */ VALUE ruby_xml_node_space_preserve_get(VALUE self) {
Control whether this node preserves whitespace.
/* * call-seq: * node.space_preserve = true|false * * Control whether this node preserves whitespace. */ VALUE ruby_xml_node_space_preserve_set(VALUE self, VALUE bool) {
Specifies if this is a text node
# File lib/libxml/node.rb, line 244 244: def text? 245: node_type == TEXT_NODE 246: end
Specifies if this is an xinclude end node
# File lib/libxml/node.rb, line 249 249: def xinclude_end? 250: node_type == XINCLUDE_END 251: end
Specifies if this is an xinclude start node
# File lib/libxml/node.rb, line 254 254: def xinclude_start? 255: node_type == XINCLUDE_START 256: end
Determine whether this node is an xlink node.
/* * call-seq: * node.xlink? -> (true|false) * * Determine whether this node is an xlink node. */ VALUE ruby_xml_node_xlink_q(VALUE self) {
Obtain the type identifier for this xlink, if applicable. If this is not an xlink node (see +xlink?+), will return nil.
/* * call-seq: * node.xlink_type -> num * * Obtain the type identifier for this xlink, if applicable. * If this is not an xlink node (see +xlink?+), will return * nil. */ VALUE ruby_xml_node_xlink_type(VALUE self) {
Obtain the type name for this xlink, if applicable. If this is not an xlink node (see +xlink?+), will return nil.
/* * call-seq: * node.xlink_type_name -> "string" * * Obtain the type name for this xlink, if applicable. * If this is not an xlink node (see +xlink?+), will return * nil. */ VALUE ruby_xml_node_xlink_type_name(VALUE self) {