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) {
Determine whether this is an attribute node,
/* * call-seq: * node.attribute? -> (true|false) * * Determine whether this is an attribute node, */ VALUE ruby_xml_node_attribute_q(VALUE self) {
Determine whether this is an attribute declaration node,
/* * call-seq: * node.attribute_decl? -> (true|false) * * Determine whether this is an attribute declaration node, */ VALUE ruby_xml_node_attribute_decl_q(VALUE self) {
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) {
Determine whether this node has properties (attributes).
/* * call-seq: * node.attributes? -> (true|false) * * Determine whether this node has properties * (attributes). */ VALUE ruby_xml_node_attributes_q(VALUE self) {
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) {
Determine whether this is a CDATA node
/* * call-seq: * node.cdata? -> (true|false) * * Determine whether this is a #CDATA node */ VALUE ruby_xml_node_cdata_q(VALUE self) {
Returns this node’s children as an array.
# File lib/libxml/node.rb, line 49 49: def children 50: entries 51: end
Determine whether this is a comment node
/* * call-seq: * node.comment? -> (true|false) * * Determine whether this is a comment node */ VALUE ruby_xml_node_comment_q(VALUE self) {
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) {
Determine whether this is a docbook node.
/* * call-seq: * node.docbook? -> (true|false) * * Determine whether this is a docbook node. */ VALUE ruby_xml_node_docbook_doc_q(VALUE self) {
Determine whether this is a DOCTYPE node.
/* * call-seq: * node.doctype? -> (true|false) * * Determine whether this is a DOCTYPE node. */ VALUE ruby_xml_node_doctype_q(VALUE self) {
Determine whether this is a document node.
/* * call-seq: * node.document? -> (true|false) * * Determine whether this is a document node. */ VALUE ruby_xml_node_document_q(VALUE self) {
Determine whether this is a DTD node.
/* * call-seq: * node.dtd? -> (true|false) * * Determine whether this is a DTD node. */ VALUE ruby_xml_node_dtd_q(VALUE self) {
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 all of 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 all of 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) {
# File lib/libxml/node.rb, line 32 32: def each_element 33: each do |node| 34: yield(node) if node.node_type == ELEMENT_NODE 35: end 36: end
Determine whether this is an element node.
/* * call-seq: * node.element? -> (true|false) * * Determine whether this is an element node. */ VALUE ruby_xml_node_element_q(VALUE self) {
Determine whether this is an element declaration node.
/* * call-seq: * node.element_decl? -> (true|false) * * Determine whether this is an element declaration node. */ VALUE ruby_xml_node_element_decl_q(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) {
Determine whether this is an entity node.
/* * call-seq: * node.entity? -> (true|false) * * Determine whether this is an entity node. */ VALUE ruby_xml_node_entity_q(VALUE self) {
Determine whether this is an entity reference node.
/* * call-seq: * node.entity_ref? -> (true|false) * * Determine whether this is an entity reference node. */ VALUE ruby_xml_node_entity_ref_q(VALUE self) {
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 10 10: def find(xpath, nslist = nil) 11: if not self.doc 12: raise(TypeError, "A node must belong to a document before " + 13: "it can be searched with XPath.") 14: end 15: 16: context = XPath::Context.new(self) 17: context.node = self 18: context.register_namespaces_from_node(self) 19: context.register_namespaces_from_node(self.doc.root) 20: context.register_namespaces(nslist) if nslist 21: 22: context.find(xpath) 23: 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 28 28: def find_first(xpath, nslist = nil) 29: find(xpath, nslist).first 30: 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 44 44: def first? 45: not first.nil? 46: end
Determine whether this node is a fragment.
/* * call-seq: * node.fragment? -> (true|false) * * Determine whether this node is a fragment. */ VALUE ruby_xml_node_fragment_q(VALUE self) {
Determine whether this node is an html document node.
/* * call-seq: * node.html_doc? -> (true|false) * * Determine whether this node is an html document node. */ VALUE ruby_xml_node_html_doc_q(VALUE self) {
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 64 64: def last? 65: not last.nil? 66: 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) {
Determine whether this node is (not has) a namespace node.
/* * call-seq: * node.namespace? -> (true|false) * * Determine whether this node *is* (not has) a namespace * node. */ VALUE ruby_xml_node_namespace_q(VALUE self) {
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 54 54: def next? 55: not self.next.nil? 56: 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 69 69: def node_type_name 70: case node_type 71: when ELEMENT_NODE: 72: 'element' 73: when ATTRIBUTE_NODE: 74: 'attribute' 75: when TEXT_NODE: 76: 'text' 77: when CDATA_SECTION_NODE: 78: 'cdata' 79: when ENTITY_REF_NODE: 80: 'entity_ref' 81: when ENTITY_NODE: 82: 'entity' 83: when PI_NODE: 84: 'pi' 85: when COMMENT_NODE: 86: 'comment' 87: when DOCUMENT_NODE: 88: 'document_xml' 89: when DOCUMENT_TYPE_NODE: 90: 'doctype' 91: when DOCUMENT_FRAG_NODE: 92: 'fragment' 93: when NOTATION_NODE: 94: 'notation' 95: when HTML_DOCUMENT_NODE: 96: 'document_html' 97: when DTD_NODE: 98: 'dtd' 99: when ELEMENT_DECL: 100: 'elem_decl' 101: when ATTRIBUTE_DECL: 102: 'attribute_decl' 103: when ENTITY_DECL: 104: 'entity_decl' 105: when NAMESPACE_DECL: 106: 'namespace' 107: when XINCLUDE_START: 108: 'xinclude_start' 109: when XINCLUDE_END: 110: 'xinclude_end' 111: when DOCB_DOCUMENT_NODE: 112: 'document_docbook' 113: else 114: raise(UnknownType, "Unknown node type: %n", node.node_type); 115: end 116: end
Determine whether this is a notation node
/* * call-seq: * node.notation? -> (true|false) * * Determine whether this is a notation node */ VALUE ruby_xml_node_notation_q(VALUE self) {
Determine whether this node is a namespace node.
/* * call-seq: * node.ns? -> (true|false) * * Determine whether this node is a namespace node. */ 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 39 39: def parent? 40: not parent.nil? 41: end
Obtain this node’s path.
/* * call-seq: * node.path -> path * * Obtain this node's path. */ VALUE ruby_xml_node_path(VALUE self) {
Determine whether this is a processing instruction node.
/* * call-seq: * node.pi? -> (true|false) * * Determine whether this is a processing instruction node. */ VALUE ruby_xml_node_pi_q(VALUE self) {
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 59 59: def prev? 60: not prev.nil? 61: 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) {
Determine whether this node has text.
/* * call-seq: * node.text? -> (true|false) * * Determine whether this node has text. */ VALUE ruby_xml_node_text_q(VALUE self) {
Determine whether this node is an xinclude end node.
/* * call-seq: * node.xinclude_end? -> num * * Determine whether this node is an xinclude end node. */ VALUE ruby_xml_node_xinclude_end_q(VALUE self) {
Determine whether this node is an xinclude start node.
/* * call-seq: * node.xinclude_start? -> num * * Determine whether this node is an xinclude start node. */ VALUE ruby_xml_node_xinclude_start_q(VALUE self) {
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) {