Class: LibXML::XML::Node
- Inherits:
-
Object
- Object
- LibXML::XML::Node
- Includes:
- Enumerable
- Defined in:
- ext/libxml/ruby_xml_node.c,
lib/libxml/node.rb,
lib/libxml/properties.rb,
ext/libxml/ruby_xml_node.c
Overview
Nodes are the primary objects that make up an XML document. The node class represents most node types that are found in an XML document (but not LibXML::XML::Attributes, see LibXML::XML::Attr). It exposes libxml’s full API for creating, querying moving and deleting node objects. Many of these methods are documented in the DOM Level 3 specification found at: www.w3.org/TR/DOM-Level-3-Core/.
Constant Summary collapse
- 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 =
Qnil
Class Method Summary collapse
-
.XML::Node.new_cdata(content = nil) ⇒ XML::Node
Create a new #CDATA node, optionally setting the node’s content.
-
.XML::Node.new_comment(content = nil) ⇒ XML::Node
Create a new comment node, optionally setting the node’s content.
-
.XML::Node.new_text(content) ⇒ XML::Node
Create a new text node.
Instance Method Summary collapse
-
#<<(obj) ⇒ Object
Add the specified text or XML::Node as a new child node to the current node.
-
#[](name) ⇒ Object
Obtain the named pyroperty.
-
#[]=("name") ⇒ Object
Set the named property.
-
#attribute? ⇒ Boolean
Specifies if this is an attribute node.
-
#attribute_decl? ⇒ Boolean
Specifies if this is an attribute declaration node.
-
#attributes ⇒ Object
Returns the XML::Attributes for this node.
-
#attributes? ⇒ Boolean
Determines whether this node has attributes.
- #base ⇒ Object
- #base=(value) ⇒ Object
-
#base_uri ⇒ Object
Obtain this node’s base URI.
-
#base_uri=(uri) ⇒ Object
Set this node’s base URI.
-
#empty? ⇒ Boolean
Determine whether this node is empty.
-
#cdata? ⇒ Boolean
Specifies if this is an CDATA node.
- #child=(node) ⇒ Object
-
#child_add(node) ⇒ Object
— Deprecated DOM Manipulation —.
-
#children ⇒ Object
Returns this node’s children as an array.
-
#clone ⇒ Object
Create a shallow copy of the node.
-
#comment? ⇒ Boolean
Specifies if this is an comment node.
-
#content ⇒ Object
Obtain this node’s content as a string.
-
#content=(content) ⇒ Object
Set this node’s content to the specified string.
-
#content_stripped ⇒ Object
Obtain this node’s stripped content.
-
#context(nslist = nil) ⇒ Object
call-seq: node.context(namespaces=nil) -> XPath::Context.
-
#copy ⇒ XML::Node
Creates a copy of this node.
-
#debug ⇒ Object
Print libxml debugging information to stdout.
-
#doc ⇒ Object
Obtain the XML::Document this node belongs to.
-
#docbook_doc? ⇒ Boolean
Specifies if this is an docbook node.
-
#doctype? ⇒ Boolean
Specifies if this is an docbook node.
-
#document? ⇒ Boolean
Specifies if this is an DOCTYPE node.
-
#dtd? ⇒ Boolean
Specifies if this is an DTD node.
-
#dump ⇒ Object
— Deprecated Output — :stopdoc:.
-
#dup ⇒ Object
:call-seq: node.dup -> XML::Node.
-
#each ⇒ XML::Node
(also: #each_child)
Iterates over this node’s children, including text nodes, element nodes, etc.
-
#each_attr ⇒ Object
——- Traversal —————- Iterates over this node’s attributes.
-
#each_element ⇒ Object
Iterates over this node’s child elements (nodes that have a node_type == ELEMENT_NODE).
-
#element? ⇒ Boolean
Specifies if this is an element node.
-
#element_decl? ⇒ Boolean
Specifies if this is an element declaration node.
-
#empty? ⇒ Boolean
Determine whether this node is empty.
-
#entity? ⇒ Boolean
Specifies if this is an entity node.
-
#entity_ref? ⇒ Boolean
Specifies if this is an entity reference node.
-
#eql?(other_node) ⇒ Boolean
(also: #==)
Test equality between the two nodes.
-
#find(xpath, nslist = nil) ⇒ Object
call-seq: node.find(namespaces=nil) -> XPath::XPathObject.
-
#find_first(xpath, nslist = nil) ⇒ Object
call-seq: node.find_first(namespaces=nil) -> XML::Node.
-
#first ⇒ XML::Node
(also: #child)
Returns this node’s first child node if any.
-
#first? ⇒ Boolean
(also: #child?, #children?)
Determines whether this node has a first node.
-
#fragment? ⇒ Boolean
Specifies if this is a fragment node.
-
#html_doc? ⇒ Boolean
Specifies if this is a html document node.
-
#XML::Node.initialize(name, content = nil, namespace = nil) ⇒ XML::Node
constructor
Creates a new element with the specified name, content and namespace.
-
#inner_xml(options = Hash.new) ⇒ Object
call-seq: node.inner_xml -> “string” node.inner_xml(:indent => true, :encoding => ‘UTF-8’, :level => 0) -> “string”.
-
#lang ⇒ Object
Obtain the language set for this node, if any.
-
#lang=(lang) ⇒ Object
Set the language for this node.
-
#last ⇒ XML::Node
Obtain the last child node of this node, if any.
-
#last? ⇒ Boolean
Determines whether this node has a last node.
-
#line_num ⇒ Numeric
Obtain the line number (in the XML document) that this node was read from.
-
#name ⇒ Object
Obtain this node’s name.
-
#name=(name) ⇒ Object
Set this node’s name.
-
#namespace ⇒ Object
— Deprecated Namespaces —.
- #namespace=(value) ⇒ Object
-
#namespace? ⇒ Boolean
Specifies if this is a namespace node (not if it has a namepsace).
- #namespace_node ⇒ Object
-
#namespaces ⇒ Object
call-seq: node.namespacess -> XML::Namespaces Returns this node’s XML::Namespaces object, which is used to access the namespaces associated with this node.
-
#next ⇒ XML::Node
Returns the next sibling node if one exists.
-
#next=(node) ⇒ Object
Adds the specified node as the next sibling of the current node.
-
#next? ⇒ Boolean
Determines whether this node has a next node.
-
#type ⇒ Numeric
Obtain this node’s type identifier.
-
#node_type_name ⇒ Object
Returns this node’s type name.
-
#notation? ⇒ Boolean
Specifies if this is a notation node.
- #ns ⇒ Object
- #ns? ⇒ Boolean
- #ns_def ⇒ Object
- #ns_def? ⇒ Boolean
-
#output_escaping=(bool) ⇒ Object
Controls whether this text node or the immediate text node children of an element or attribute node escapes their output.
-
#output_escaping? ⇒ Boolean
Determine whether this node escapes it’s output or not.
-
#parent ⇒ XML::Node
Obtain this node’s parent node, if any.
-
#parent? ⇒ Boolean
Determines whether this node has a parent node.
-
#path ⇒ Object
Obtain this node’s path.
-
#pi? ⇒ Boolean
Specifies if this is a processiong instruction node.
-
#pointer ⇒ XML::NodeSet
Evaluates an XPointer expression relative to this node.
-
#prev ⇒ XML::Node
Obtain the previous sibling, if any.
-
#prev=(node) ⇒ Object
Adds the specified node as the previous sibling of the current node.
-
#prev? ⇒ Boolean
Determines whether this node has a previous node.
- #properties ⇒ Object
- #properties? ⇒ Boolean
- #property(name) ⇒ Object
-
#remove! ⇒ Object
Removes this node and its children from the document tree by setting its document, parent and siblings to nil.
- #search_href(href) ⇒ Object
- #search_ns(prefix) ⇒ Object
-
#sibling=(node) ⇒ Object
Adds the specified node as the end of the current node’s list of siblings.
-
#space_preserve ⇒ Object
Determine whether this node preserves whitespace.
-
#space_preserve=(true) ⇒ Object
Control whether this node preserves whitespace.
-
#text? ⇒ Boolean
Specifies if this is a text node.
-
#to_s(*args) ⇒ Object
Converts a node, and all of its children, to a string representation.
-
#xinclude_end? ⇒ Boolean
Specifies if this is an xinclude end node.
-
#xinclude_start? ⇒ Boolean
Specifies if this is an xinclude start node.
-
#xlink? ⇒ Boolean
Determine whether this node is an xlink node.
-
#xlink_type ⇒ Numeric
Obtain the type identifier for this xlink, if applicable.
-
#xlink_type_name ⇒ Object
Obtain the type name for this xlink, if applicable.
Constructor Details
#XML::Node.initialize(name, content = nil, namespace = nil) ⇒ XML::Node
Creates a new element with the specified name, content and namespace. The content and namespace may be nil.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'ext/libxml/ruby_xml_node.c', line 202
static VALUE rxml_node_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE name;
VALUE content;
VALUE ns;
xmlNodePtr xnode = NULL;
xmlNsPtr xns = NULL;
rb_scan_args(argc, argv, "12", &name, &content, &ns);
name = rb_obj_as_string(name);
if (!NIL_P(ns))
Data_Get_Struct(ns, xmlNs, xns);
xnode = xmlNewNode(xns, (xmlChar*) StringValuePtr(name));
if (xnode == NULL)
rxml_raise(&xmlLastError);
/* Link the Ruby object to the libxml object and vice-versa. */
xnode->_private = (void*) self;
DATA_PTR(self) = xnode;
if (!NIL_P(content))
rxml_node_content_set(self, content);
return self;
}
|
Class Method Details
.XML::Node.new_cdata(content = nil) ⇒ XML::Node
Create a new #CDATA node, optionally setting the node’s content.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'ext/libxml/ruby_xml_node.c', line 117
static VALUE rxml_node_new_cdata(int argc, VALUE *argv, VALUE klass)
{
VALUE content = Qnil;
xmlNodePtr xnode;
rb_scan_args(argc, argv, "01", &content);
if (NIL_P(content))
{
xnode = xmlNewCDataBlock(NULL, NULL, 0);
}
else
{
content = rb_obj_as_string(content);
xnode = xmlNewCDataBlock(NULL, (xmlChar*) StringValuePtr(content),
RSTRING_LEN(content));
}
if (xnode == NULL)
rxml_raise(&xmlLastError);
return rxml_node_wrap(xnode);
}
|
.XML::Node.new_comment(content = nil) ⇒ XML::Node
Create a new comment node, optionally setting the node’s content.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'ext/libxml/ruby_xml_node.c', line 149
static VALUE rxml_node_new_comment(int argc, VALUE *argv, VALUE klass)
{
VALUE content = Qnil;
xmlNodePtr xnode;
rb_scan_args(argc, argv, "01", &content);
if (NIL_P(content))
{
xnode = xmlNewComment(NULL);
}
else
{
content = rb_obj_as_string(content);
xnode = xmlNewComment((xmlChar*) StringValueCStr(content));
}
if (xnode == NULL)
rxml_raise(&xmlLastError);
return rxml_node_wrap(xnode);
}
|
.XML::Node.new_text(content) ⇒ XML::Node
Create a new text node.
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'ext/libxml/ruby_xml_node.c', line 179
static VALUE rxml_node_new_text(VALUE klass, VALUE content)
{
xmlNodePtr xnode;
Check_Type(content, T_STRING);
content = rb_obj_as_string(content);
xnode = xmlNewText((xmlChar*) StringValueCStr(content));
if (xnode == NULL)
rxml_raise(&xmlLastError);
return rxml_node_wrap(xnode);
}
|
Instance Method Details
#<<("Some text") ⇒ Object #<<(node) ⇒ Object
Add the specified text or XML::Node as a new child node to the current node.
If the specified argument is a string, it should be a raw string that contains unescaped XML special characters. Entity references are not supported.
The method will return the current node.
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'ext/libxml/ruby_xml_node.c', line 432
static VALUE rxml_node_content_add(VALUE self, VALUE obj)
{
xmlNodePtr xnode;
VALUE str;
Data_Get_Struct(self, xmlNode, xnode);
/* XXX This should only be legal for a CDATA type node, I think,
* resulting in a merge of content, as if a string were passed
* danj 070827
*/
if (rb_obj_is_kind_of(obj, cXMLNode))
{
xmlNodePtr xtarget;
Data_Get_Struct(obj, xmlNode, xtarget);
xmlUnlinkNode(xtarget);
rxml_node_modify_dom(self, obj, xmlAddChild);
}
else
{
str = rb_obj_as_string(obj);
if (NIL_P(str) || TYPE(str) != T_STRING)
rb_raise(rb_eTypeError, "invalid argument: must be string or XML::Node");
xmlNodeAddContent(xnode, (xmlChar*) StringValuePtr(str));
}
return self;
}
|
#property("name") ⇒ Object #[]("name") ⇒ Object
Obtain the named pyroperty.
1050 1051 1052 1053 1054 |
# File 'ext/libxml/ruby_xml_node.c', line 1050
static VALUE rxml_node_attribute_get(VALUE self, VALUE name)
{
VALUE attributes = rxml_node_attributes_get(self);
return rxml_attributes_attribute_get(attributes, name);
}
|
#[]=("name") ⇒ Object
Set the named property.
1062 1063 1064 1065 1066 |
# File 'ext/libxml/ruby_xml_node.c', line 1062
static VALUE rxml_node_property_set(VALUE self, VALUE name, VALUE value)
{
VALUE attributes = rxml_node_attributes_get(self);
return rxml_attributes_attribute_set(attributes, name, value);
}
|
#attribute? ⇒ Boolean
Specifies if this is an attribute node
203 204 205 |
# File 'lib/libxml/node.rb', line 203 def attribute? node_type == ATTRIBUTE_NODE end |
#attribute_decl? ⇒ Boolean
Specifies if this is an attribute declaration node
208 209 210 |
# File 'lib/libxml/node.rb', line 208 def attribute_decl? node_type == ATTRIBUTE_DECL end |
#attributes ⇒ Object
Returns the XML::Attributes for this node.
1035 1036 1037 1038 1039 1040 1041 |
# File 'ext/libxml/ruby_xml_node.c', line 1035
static VALUE rxml_node_attributes_get(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
return rxml_attributes_new(xnode);
}
|
#attributes? ⇒ Boolean
Determines whether this node has attributes
7 8 9 |
# File 'lib/libxml/node.rb', line 7 def attributes? attributes.length > 0 end |
#base ⇒ Object
362 363 364 365 |
# File 'lib/libxml/node.rb', line 362 def base warn('Node#base is deprecated. Use Node#base_uri.') self.base_uri end |
#base=(value) ⇒ Object
367 368 369 370 |
# File 'lib/libxml/node.rb', line 367 def base=(value) warn('Node#base= is deprecated. Use Node#base_uri=.') self.base_uri = value end |
#base_uri ⇒ Object
Obtain this node’s base URI.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'ext/libxml/ruby_xml_node.c', line 268
static VALUE rxml_node_base_uri_get(VALUE self)
{
xmlNodePtr xnode;
xmlChar* base_uri;
VALUE result = Qnil;
Data_Get_Struct(self, xmlNode, xnode);
if (xnode->doc == NULL)
return (result);
base_uri = xmlNodeGetBase(xnode->doc, xnode);
if (base_uri)
{
result = rb_str_new2((const char*) base_uri);
xmlFree(base_uri);
}
return (result);
}
|
#base_uri=(uri) ⇒ Object
Set this node’s base URI.
297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'ext/libxml/ruby_xml_node.c', line 297
static VALUE rxml_node_base_uri_set(VALUE self, VALUE uri)
{
xmlNodePtr xnode;
Check_Type(uri, T_STRING);
Data_Get_Struct(self, xmlNode, xnode);
if (xnode->doc == NULL)
return (Qnil);
xmlNodeSetBase(xnode, (xmlChar*) StringValuePtr(uri));
return (Qtrue);
}
|
#empty? ⇒ Boolean
Determine whether this node is empty.
622 623 624 625 626 627 628 629 630 |
# File 'ext/libxml/ruby_xml_node.c', line 622
static VALUE rxml_node_empty_q(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
if (xnode == NULL)
return (Qnil);
return ((xmlIsBlankNode(xnode) == 1) ? Qtrue : Qfalse);
}
|
#cdata? ⇒ Boolean
Specifies if this is an CDATA node
213 214 215 |
# File 'lib/libxml/node.rb', line 213 def cdata? node_type == CDATA_SECTION_NODE end |
#child=(node) ⇒ Object
321 322 323 324 |
# File 'lib/libxml/node.rb', line 321 def child=(node) warn('Node#child= is deprecated. Use Node#<< instead.') self << node end |
#child_add(node) ⇒ Object
— Deprecated DOM Manipulation —
316 317 318 319 |
# File 'lib/libxml/node.rb', line 316 def child_add(node) warn('Node#child_add is deprecated. Use Node#<< instead.') self << node end |
#children ⇒ Object
Returns this node’s children as an array.
127 128 129 |
# File 'lib/libxml/node.rb', line 127 def children entries end |
#clone ⇒ Object
Create a shallow copy of the node. To create a deep copy call Node#copy(true)
13 14 15 |
# File 'lib/libxml/node.rb', line 13 def clone copy(false) end |
#comment? ⇒ Boolean
Specifies if this is an comment node
218 219 220 |
# File 'lib/libxml/node.rb', line 218 def comment? node_type == COMMENT_NODE end |
#content ⇒ Object
Obtain this node’s content as a string.
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'ext/libxml/ruby_xml_node.c', line 316
static VALUE rxml_node_content_get(VALUE self)
{
xmlNodePtr xnode;
xmlChar *content;
VALUE result = Qnil;
Data_Get_Struct(self, xmlNode, xnode);
content = xmlNodeGetContent(xnode);
if (content)
{
result = rb_str_new2((const char *) content);
xmlFree(content);
}
return result;
}
|
#content=(content) ⇒ Object
Set this node’s content to the specified string.
339 340 341 342 343 344 345 346 347 348 |
# File 'ext/libxml/ruby_xml_node.c', line 339
static VALUE rxml_node_content_set(VALUE self, VALUE content)
{
xmlNodePtr xnode;
Check_Type(content, T_STRING);
Data_Get_Struct(self, xmlNode, xnode);
// XXX docs indicate need for escaping entites, need to be done? danj
xmlNodeSetContent(xnode, (xmlChar*) StringValuePtr(content));
return (Qtrue);
}
|
#content_stripped ⇒ Object
Obtain this node’s stripped content.
Deprecated: Stripped content can be obtained via the content
method.
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'ext/libxml/ruby_xml_node.c', line 359
static VALUE rxml_node_content_stripped_get(VALUE self)
{
xmlNodePtr xnode;
xmlChar* content;
VALUE result = Qnil;
Data_Get_Struct(self, xmlNode, xnode);
if (!xnode->content)
return result;
content = xmlNodeGetContent(xnode);
if (content)
{
result = rb_str_new2((const char*) content);
xmlFree(content);
}
return (result);
}
|
#context(nslist = nil) ⇒ Object
call-seq:
node.context(namespaces=nil) -> XPath::Context
Returns a new XML::XPathContext for the current node.
Namespaces is an optional array of XML::NS objects
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/libxml/node.rb', line 49 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) 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 |
#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.
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 |
# File 'ext/libxml/ruby_xml_node.c', line 1266
static VALUE rxml_node_copy(VALUE self, VALUE deep)
{
xmlNodePtr xnode;
xmlNodePtr xcopy;
int recursive = (deep == Qnil || deep == Qfalse) ? 0 : 1;
Data_Get_Struct(self, xmlNode, xnode);
xcopy = xmlCopyNode(xnode, recursive);
if (xcopy)
return rxml_node_wrap(xcopy);
else
return Qnil;
}
|
#debug ⇒ Object
Print libxml debugging information to stdout. Requires that libxml was compiled with debugging enabled.
386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'ext/libxml/ruby_xml_node.c', line 386
static VALUE rxml_node_debug(VALUE self)
{
#ifdef LIBXML_DEBUG_ENABLED
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
xmlDebugDumpNode(NULL, xnode, 2);
return Qtrue;
#else
rb_warn("libxml was compiled without debugging support.")
return Qfalse;
#endif
}
|
#doc ⇒ Object
Obtain the XML::Document this node belongs to.
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'ext/libxml/ruby_xml_node.c', line 466
static VALUE rxml_node_doc(VALUE self)
{
xmlNodePtr xnode;
xmlDocPtr doc = NULL;
Data_Get_Struct(self, xmlNode, xnode);
switch (xnode->type)
{
case XML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_HTML_DOCUMENT_NODE:
doc = NULL;
break;
case XML_ATTRIBUTE_NODE:
{
xmlAttrPtr attr = (xmlAttrPtr) xnode;
doc = attr->doc;
break;
}
case XML_NAMESPACE_DECL:
doc = NULL;
break;
default:
doc = xnode->doc;
break;
}
if (doc == NULL)
return (Qnil);
if (doc->_private == NULL)
rb_raise(rb_eRuntimeError, "existing document object has no ruby-instance");
return (VALUE) doc->_private;
}
|
#docbook_doc? ⇒ Boolean
Specifies if this is an docbook node
223 224 225 |
# File 'lib/libxml/node.rb', line 223 def docbook_doc? node_type == DOCB_DOCUMENT_NODE end |
#doctype? ⇒ Boolean
Specifies if this is an docbook node
228 229 230 |
# File 'lib/libxml/node.rb', line 228 def doctype? node_type == DOCUMENT_TYPE_NODE end |
#document? ⇒ Boolean
Specifies if this is an DOCTYPE node
233 234 235 |
# File 'lib/libxml/node.rb', line 233 def document? node_type == DOCUMENT_NODE end |
#dtd? ⇒ Boolean
Specifies if this is an DTD node
238 239 240 |
# File 'lib/libxml/node.rb', line 238 def dtd? node_type == DTD_NODE end |
#dump ⇒ Object
— Deprecated Output — :stopdoc:
310 311 312 313 |
# File 'lib/libxml/node.rb', line 310 def dump warn('Node#dump is deprecated. Use Node#to_s instead.') self.to_s end |
#dup ⇒ Object
:call-seq:
node.dup -> XML::Node
Create a shallow copy of the node. To create a deep copy call Node#copy(true)
39 40 41 |
# File 'lib/libxml/node.rb', line 39 def dup copy(false) end |
#each ⇒ XML::Node Also known as: each_child
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'ext/libxml/ruby_xml_node.c', line 596
static VALUE rxml_node_each(VALUE self)
{
xmlNodePtr xnode;
xmlNodePtr xcurrent;
Data_Get_Struct(self, xmlNode, xnode);
xcurrent = xnode->children;
while (xcurrent)
{
/* The user could remove this node, so first stache
away the next node. */
xmlNodePtr xnext = xcurrent->next;
rb_yield(rxml_node_wrap(xcurrent));
xcurrent = xnext;
}
return Qnil;
}
|
#each_attr ⇒ Object
99 100 101 102 103 |
# File 'lib/libxml/node.rb', line 99 def each_attr attributes.each do |attr| yield(attr) end end |
#each_element ⇒ Object
110 111 112 113 114 |
# File 'lib/libxml/node.rb', line 110 def each_element each do |node| yield(node) if node.node_type == ELEMENT_NODE end end |
#element? ⇒ Boolean
Specifies if this is an element node
243 244 245 |
# File 'lib/libxml/node.rb', line 243 def element? node_type == ELEMENT_NODE end |
#element_decl? ⇒ Boolean
Specifies if this is an element declaration node
253 254 255 |
# File 'lib/libxml/node.rb', line 253 def element_decl? node_type == ELEMENT_DECL end |
#empty? ⇒ Boolean
Determine whether this node is empty.
622 623 624 625 626 627 628 629 630 |
# File 'ext/libxml/ruby_xml_node.c', line 622
static VALUE rxml_node_empty_q(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
if (xnode == NULL)
return (Qnil);
return ((xmlIsBlankNode(xnode) == 1) ? Qtrue : Qfalse);
}
|
#entity? ⇒ Boolean
Specifies if this is an entity node
248 249 250 |
# File 'lib/libxml/node.rb', line 248 def entity? node_type == ENTITY_NODE end |
#entity_ref? ⇒ Boolean
Specifies if this is an entity reference node
258 259 260 |
# File 'lib/libxml/node.rb', line 258 def entity_ref? node_type == ENTITY_REF_NODE end |
#eql?(other_node) ⇒ Boolean Also known as: ==
Test equality between the two nodes. Two nodes are equal if they are the same node or have the same XML representation.
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'ext/libxml/ruby_xml_node.c', line 639
static VALUE rxml_node_eql_q(VALUE self, VALUE other)
{
if(self == other)
{
return Qtrue;
}
else if (NIL_P(other))
{
return Qfalse;
}
else
{
VALUE self_xml;
VALUE other_xml;
if (rb_obj_is_kind_of(other, cXMLNode) == Qfalse)
rb_raise(rb_eTypeError, "Nodes can only be compared against other nodes");
self_xml = rxml_node_to_s(0, NULL, self);
other_xml = rxml_node_to_s(0, NULL, other);
return(rb_funcall(self_xml, rb_intern("=="), 1, other_xml));
}
}
|
#find(xpath, nslist = nil) ⇒ Object
call-seq:
node.find(namespaces=nil) -> XPath::XPathObject
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
70 71 72 |
# File 'lib/libxml/node.rb', line 70 def find(xpath, nslist = nil) self.context(nslist).find(xpath) end |
#find_first(xpath, nslist = nil) ⇒ Object
call-seq:
node.find_first(namespaces=nil) -> XML::Node
Return the first node matching the specified xpath expression. For more information, please refer to the documentation for the #find method.
80 81 82 |
# File 'lib/libxml/node.rb', line 80 def find_first(xpath, nslist = nil) find(xpath, nslist).first end |
#first ⇒ XML::Node Also known as: child
Returns this node’s first child node if any.
405 406 407 408 409 410 411 412 413 414 415 |
# File 'ext/libxml/ruby_xml_node.c', line 405
static VALUE rxml_node_first_get(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
if (xnode->children)
return (rxml_node_wrap(xnode->children));
else
return (Qnil);
}
|
#first? ⇒ Boolean Also known as: child?, children?
Determines whether this node has a first node
122 123 124 |
# File 'lib/libxml/node.rb', line 122 def first? not first.nil? end |
#fragment? ⇒ Boolean
Specifies if this is a fragment node
263 264 265 |
# File 'lib/libxml/node.rb', line 263 def fragment? node_type == DOCUMENT_FRAG_NODE end |
#html_doc? ⇒ Boolean
Specifies if this is a html document node
268 269 270 |
# File 'lib/libxml/node.rb', line 268 def html_doc? node_type == HTML_DOCUMENT_NODE end |
#inner_xml(options = Hash.new) ⇒ Object
call-seq:
node.inner_xml -> "string"
node.inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string"
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.
24 25 26 27 28 29 30 31 32 |
# File 'lib/libxml/node.rb', line 24 def inner_xml( = Hash.new) io = StringIO.new self.each do |node| io << node.to_s() end io.string end |
#lang ⇒ Object
Obtain the language set for this node, if any. This is set in XML via the xml:lang attribute.
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
# File 'ext/libxml/ruby_xml_node.c', line 670
static VALUE rxml_node_lang_get(VALUE self)
{
xmlNodePtr xnode;
xmlChar *lang;
VALUE result = Qnil;
Data_Get_Struct(self, xmlNode, xnode);
lang = xmlNodeGetLang(xnode);
if (lang)
{
result = rb_str_new2((const char*) lang);
xmlFree(lang);
}
return (result);
}
|
#lang=(lang) ⇒ Object
Set the language for this node. This affects the value of the xml:lang attribute.
697 698 699 700 701 702 703 704 705 706 |
# File 'ext/libxml/ruby_xml_node.c', line 697
static VALUE rxml_node_lang_set(VALUE self, VALUE lang)
{
xmlNodePtr xnode;
Check_Type(lang, T_STRING);
Data_Get_Struct(self, xmlNode, xnode);
xmlNodeSetLang(xnode, (xmlChar*) StringValuePtr(lang));
return (Qtrue);
}
|
#last ⇒ XML::Node
Obtain the last child node of this node, if any.
714 715 716 717 718 719 720 721 722 723 724 |
# File 'ext/libxml/ruby_xml_node.c', line 714
static VALUE rxml_node_last_get(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
if (xnode->last)
return (rxml_node_wrap(xnode->last));
else
return (Qnil);
}
|
#last? ⇒ Boolean
Determines whether this node has a last node
142 143 144 |
# File 'lib/libxml/node.rb', line 142 def last? not last.nil? end |
#line_num ⇒ Numeric
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.
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 |
# File 'ext/libxml/ruby_xml_node.c', line 734
static VALUE rxml_node_line_num(VALUE self)
{
xmlNodePtr xnode;
long line_num;
Data_Get_Struct(self, xmlNode, xnode);
if (!xmlLineNumbersDefaultValue)
rb_warn(
"Line numbers were not retained: use XML::Parser::default_line_numbers=true");
line_num = xmlGetLineNo(xnode);
if (line_num == -1)
return (Qnil);
else
return (INT2NUM((long) line_num));
}
|
#name ⇒ Object
Obtain this node’s name.
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'ext/libxml/ruby_xml_node.c', line 830
static VALUE rxml_node_name_get(VALUE self)
{
xmlNodePtr xnode;
const xmlChar *name;
Data_Get_Struct(self, xmlNode, xnode);
switch (xnode->type)
{
case XML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_HTML_DOCUMENT_NODE:
{
xmlDocPtr doc = (xmlDocPtr) xnode;
name = doc->URL;
break;
}
case XML_ATTRIBUTE_NODE:
{
xmlAttrPtr attr = (xmlAttrPtr) xnode;
name = attr->name;
break;
}
case XML_NAMESPACE_DECL:
{
xmlNsPtr ns = (xmlNsPtr) xnode;
name = ns->prefix;
break;
}
default:
name = xnode->name;
break;
}
if (xnode->name == NULL)
return (Qnil);
else
return (rb_str_new2((const char*) name));
}
|
#name=(name) ⇒ Object
Set this node’s name.
878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
# File 'ext/libxml/ruby_xml_node.c', line 878
static VALUE rxml_node_name_set(VALUE self, VALUE name)
{
xmlNodePtr xnode;
const xmlChar *xname;
Check_Type(name, T_STRING);
Data_Get_Struct(self, xmlNode, xnode);
xname = (const xmlChar*)StringValuePtr(name);
/* Note: calling xmlNodeSetName() for a text node is ignored by libXML. */
xmlNodeSetName(xnode, xname);
return (Qtrue);
}
|
#namespace ⇒ Object
— Deprecated Namespaces —
327 328 329 330 |
# File 'lib/libxml/node.rb', line 327 def namespace warn('Node#namespace is deprecated. Use Node#namespaces instead.') self.namespaces.entries end |
#namespace=(value) ⇒ Object
332 333 334 335 |
# File 'lib/libxml/node.rb', line 332 def namespace=(value) warn('Node#namespace= is deprecated. Use Node#namespaces.namespace= instead.') self.namespaces.namespace = value end |
#namespace? ⇒ Boolean
Specifies if this is a namespace node (not if it has a namepsace)
274 275 276 |
# File 'lib/libxml/node.rb', line 274 def namespace? node_type == NAMESPACE_DECL end |
#namespace_node ⇒ Object
337 338 339 340 |
# File 'lib/libxml/node.rb', line 337 def namespace_node warn('Node#namespace_node is deprecated. Use Node#namespaces.namespace instead.') self.namespaces.namespace end |
#namespaces ⇒ Object
call-seq:
node.namespacess -> XML::Namespaces
Returns this node’s XML::Namespaces object, which is used to access the namespaces associated with this node.
90 91 92 |
# File 'lib/libxml/node.rb', line 90 def namespaces @namespaces ||= XML::Namespaces.new(self) end |
#next ⇒ XML::Node
Returns the next sibling node if one exists.
899 900 901 902 903 904 905 906 907 908 909 |
# File 'ext/libxml/ruby_xml_node.c', line 899
static VALUE rxml_node_next_get(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
if (xnode->next)
return (rxml_node_wrap(xnode->next));
else
return (Qnil);
}
|
#next=(node) ⇒ Object
Adds the specified node as the next sibling of the current node. If the node already exists in the document, it is first removed from its existing context. Any adjacent text nodes will be merged together, meaning the returned node may be different than the original node.
921 922 923 924 |
# File 'ext/libxml/ruby_xml_node.c', line 921
static VALUE rxml_node_next_set(VALUE self, VALUE next)
{
return rxml_node_modify_dom(self, next, xmlAddNextSibling);
}
|
#next? ⇒ Boolean
Determines whether this node has a next node
132 133 134 |
# File 'lib/libxml/node.rb', line 132 def next? not self.next.nil? end |
#type ⇒ Numeric
Obtain this node’s type identifier.
1249 1250 1251 1252 1253 1254 |
# File 'ext/libxml/ruby_xml_node.c', line 1249
static VALUE rxml_node_type(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
return (INT2NUM(xnode->type));
}
|
#node_type_name ⇒ Object
Returns this node’s type name
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/libxml/node.rb', line 150 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 |
#notation? ⇒ Boolean
Specifies if this is a notation node
279 280 281 |
# File 'lib/libxml/node.rb', line 279 def notation? node_type == NOTATION_NODE end |
#ns ⇒ Object
342 343 344 345 |
# File 'lib/libxml/node.rb', line 342 def ns warn('Node#ns is deprecated. Use Node#namespaces.namespace instead.') self.namespaces.namespace end |
#ns? ⇒ Boolean
347 348 349 350 |
# File 'lib/libxml/node.rb', line 347 def ns? warn('Node#ns? is deprecated. Use !Node#namespaces.namespace.nil? instead.') !self.namespaces.namespace.nil? end |
#ns_def ⇒ Object
352 353 354 355 |
# File 'lib/libxml/node.rb', line 352 def ns_def warn('Node#ns_def is deprecated. Use Node#namespaces.definitions instead.') self.namespaces.definitions end |
#ns_def? ⇒ Boolean
357 358 359 360 |
# File 'lib/libxml/node.rb', line 357 def ns_def? warn('Node#ns_def? is deprecated. Use !Node#namespaces.definitions.nil? instead.') !self.namespaces.definitions.nil? end |
#output_escaping=(true) ⇒ Object #output_escaping=(true) ⇒ Object #output_escaping=(true) ⇒ Object
Controls whether this text node or the immediate text node children of an element or attribute node escapes their output. Any other type of node will simply ignore this operation.
Text nodes which are added to an element or attribute node will be affected by any previous setting of this property.
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 |
# File 'ext/libxml/ruby_xml_node.c', line 1184
static VALUE rxml_node_output_escaping_set(VALUE self, VALUE bool)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
switch (xnode->type) {
case XML_TEXT_NODE:
xnode->name = (bool!=Qfalse && bool!=Qnil) ? xmlStringText : xmlStringTextNoenc;
break;
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
{
const xmlChar *name = (bool!=Qfalse && bool!=Qnil) ? xmlStringText : xmlStringTextNoenc;
xmlNodePtr tmp;
for (tmp = xnode->children; tmp; tmp = tmp->next)
if (tmp->type == XML_TEXT_NODE)
tmp->name = name;
}
break;
default:
return Qnil;
}
return (bool!=Qfalse && bool!=Qnil) ? Qtrue : Qfalse;
}
|
#output_escaping? ⇒ Boolean #output_escaping? ⇒ Boolean #output_escaping? ⇒ Boolean #output_escaping? ⇒ Boolean
Determine whether this node escapes it’s output or not.
Text nodes return only true
or false
. Element and attribute nodes examine their immediate text node children to determine the value. Any other type of node always returns nil
.
If an element or attribute node has at least one immediate child text node and all the immediate text node children have the same output_escaping?
value, that value is returned. Otherwise, nil
is returned.
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 |
# File 'ext/libxml/ruby_xml_node.c', line 1137
static VALUE rxml_node_output_escaping_q(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
switch (xnode->type) {
case XML_TEXT_NODE:
return xnode->name==xmlStringTextNoenc ? Qfalse : Qtrue;
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
{
xmlNodePtr tmp = xnode->children;
const xmlChar *match = NULL;
/* Find the first text node and use it as the reference. */
while (tmp && tmp->type != XML_TEXT_NODE)
tmp = tmp->next;
if (! tmp)
return Qnil;
match = tmp->name;
/* Walk the remaining text nodes until we run out or one doesn't match. */
while (tmp && (tmp->type != XML_TEXT_NODE || match == tmp->name))
tmp = tmp->next;
/* We're left with either the mismatched node or the aggregate result. */
return tmp ? Qnil : (match==xmlStringTextNoenc ? Qfalse : Qtrue);
}
break;
default:
return Qnil;
}
}
|
#parent ⇒ XML::Node
Obtain this node’s parent node, if any.
932 933 934 935 936 937 938 939 940 941 942 |
# File 'ext/libxml/ruby_xml_node.c', line 932
static VALUE rxml_node_parent_get(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
if (xnode->parent)
return (rxml_node_wrap(xnode->parent));
else
return (Qnil);
}
|
#parent? ⇒ Boolean
Determines whether this node has a parent node
117 118 119 |
# File 'lib/libxml/node.rb', line 117 def parent? not parent.nil? end |
#path ⇒ Object
Obtain this node’s path.
950 951 952 953 954 955 956 957 958 959 960 961 962 |
# File 'ext/libxml/ruby_xml_node.c', line 950
static VALUE rxml_node_path(VALUE self)
{
xmlNodePtr xnode;
xmlChar *path;
Data_Get_Struct(self, xmlNode, xnode);
path = xmlGetNodePath(xnode);
if (path == NULL)
return (Qnil);
else
return (rb_str_new2((const char*) path));
}
|
#pi? ⇒ Boolean
Specifies if this is a processiong instruction node
284 285 286 |
# File 'lib/libxml/node.rb', line 284 def pi? node_type == PI_NODE end |
#pointer ⇒ XML::NodeSet
Evaluates an XPointer expression relative to this node.
970 971 972 973 |
# File 'ext/libxml/ruby_xml_node.c', line 970
static VALUE rxml_node_pointer(VALUE self, VALUE xptr_str)
{
return (rxml_xpointer_point2(self, xptr_str));
}
|
#prev ⇒ XML::Node
Obtain the previous sibling, if any.
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
# File 'ext/libxml/ruby_xml_node.c', line 981
static VALUE rxml_node_prev_get(VALUE self)
{
xmlNodePtr xnode;
xmlNodePtr node;
Data_Get_Struct(self, xmlNode, xnode);
switch (xnode->type)
{
case XML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_HTML_DOCUMENT_NODE:
case XML_NAMESPACE_DECL:
node = NULL;
break;
case XML_ATTRIBUTE_NODE:
{
xmlAttrPtr attr = (xmlAttrPtr) xnode;
node = (xmlNodePtr) attr->prev;
}
break;
default:
node = xnode->prev;
break;
}
if (node == NULL)
return (Qnil);
else
return (rxml_node_wrap(node));
}
|
#prev=(node) ⇒ Object
Adds the specified node as the previous sibling of the current node. If the node already exists in the document, it is first removed from its existing context. Any adjacent text nodes will be merged together, meaning the returned node may be different than the original node.
1024 1025 1026 1027 |
# File 'ext/libxml/ruby_xml_node.c', line 1024
static VALUE rxml_node_prev_set(VALUE self, VALUE prev)
{
return rxml_node_modify_dom(self, prev, xmlAddPrevSibling);
}
|
#prev? ⇒ Boolean
Determines whether this node has a previous node
137 138 139 |
# File 'lib/libxml/node.rb', line 137 def prev? not prev.nil? end |
#properties ⇒ Object
9 10 11 12 |
# File 'lib/libxml/properties.rb', line 9 def properties warn('Node#properties is deprecated. Use Node#attributes instead.') self.attributes end |
#properties? ⇒ Boolean
14 15 16 17 |
# File 'lib/libxml/properties.rb', line 14 def properties? warn('Node#properties? is deprecated. Use Node#attributes? instead.') self.attributes? end |
#property(name) ⇒ Object
4 5 6 7 |
# File 'lib/libxml/properties.rb', line 4 def property(name) warn('Node#properties is deprecated. Use Node#[] instead.') self[name] end |
#remove! ⇒ Object
Removes this node and its children from the document tree by setting its document, parent and siblings to nil. You can add the returned node back into a document. Otherwise, the node will be freed once any references to it go out of scope.
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# File 'ext/libxml/ruby_xml_node.c', line 1077
static VALUE rxml_node_remove_ex(VALUE self)
{
xmlNodePtr xnode, xresult;
Data_Get_Struct(self, xmlNode, xnode);
/* First unlink the node from its parent. */
xmlUnlinkNode(xnode);
/* Now copy the node we want to remove and make the
current Ruby object point to it. We do this because
a node has a number of dependencies on its parent
document - its name (if using a dictionary), entities,
namespaces, etc. For a node to live on its own, it
needs to get its own copies of this information.*/
xresult = xmlDocCopyNode(xnode, NULL, 1);
/* Now free the original node. */
xmlFreeNode(xnode);
/* Now wrap the new node */
RDATA(self)->data = xresult;
xresult->_private = (void*) self;
/* Now return the removed node so the user can
do something with it.*/
return self;
}
|
#search_href(href) ⇒ Object
377 378 379 380 |
# File 'lib/libxml/node.rb', line 377 def search_href(href) warn('Node#search_href is deprecated. Use Node#namespaces.find_by_href instead.') self.namespaces.find_by_href(href) end |
#search_ns(prefix) ⇒ Object
372 373 374 375 |
# File 'lib/libxml/node.rb', line 372 def search_ns(prefix) warn('Node#search_ns is deprecated. Use Node#namespaces.find_by_prefix instead.') self.namespaces.find_by_prefix(prefix) end |
#sibling=(node) ⇒ Object
Adds the specified node as the end of the current node’s list of siblings. If the node already exists in the document, it is first removed from its existing context. Any adjacent text nodes will be merged together, meaning the returned node may be different than the original node.
1115 1116 1117 1118 |
# File 'ext/libxml/ruby_xml_node.c', line 1115
static VALUE rxml_node_sibling_set(VALUE self, VALUE sibling)
{
return rxml_node_modify_dom(self, sibling, xmlAddSibling);
}
|
#space_preserve ⇒ Object
Determine whether this node preserves whitespace.
1216 1217 1218 1219 1220 1221 1222 |
# File 'ext/libxml/ruby_xml_node.c', line 1216
static VALUE rxml_node_space_preserve_get(VALUE self)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
return (INT2NUM(xmlNodeGetSpacePreserve(xnode)));
}
|
#space_preserve=(true) ⇒ Object
Control whether this node preserves whitespace.
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 |
# File 'ext/libxml/ruby_xml_node.c', line 1230
static VALUE rxml_node_space_preserve_set(VALUE self, VALUE bool)
{
xmlNodePtr xnode;
Data_Get_Struct(self, xmlNode, xnode);
if (TYPE(bool) == T_FALSE)
xmlNodeSetSpacePreserve(xnode, 1);
else
xmlNodeSetSpacePreserve(xnode, 0);
return (Qnil);
}
|
#text? ⇒ Boolean
Specifies if this is a text node
289 290 291 |
# File 'lib/libxml/node.rb', line 289 def text? node_type == TEXT_NODE end |
#to_s ⇒ Object #to_s(: indent) ⇒ true
Converts a node, and all of its children, to a string representation. To include only the node’s children, use the the XML::Node#inner_xml method.
You may provide an optional hash table to control how the string is generated. Valid options are:
:indent - Specifies if the string should be indented. The default value is true. Note that indentation is only added if both :indent is true and XML.indent_tree_output is true. If :indent is set to false, then both indentation and line feeds are removed from the result.
:level - Specifies the indentation level. The amount of indentation is equal to the (level * number_spaces) + number_spaces, where libxml defaults the number of spaces to 2. Thus a level of 0 results in 2 spaces, level 1 results in 4 spaces, level 2 results in 6 spaces, etc.
:encoding - Specifies the output encoding of the string. It defaults to XML::Encoding::UTF8. To change it, use one of the XML::Encoding encoding constants.
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'ext/libxml/ruby_xml_node.c', line 531
static VALUE rxml_node_to_s(int argc, VALUE *argv, VALUE self)
{
VALUE result = Qnil;
VALUE options = Qnil;
xmlNodePtr xnode;
xmlCharEncodingHandlerPtr encodingHandler;
xmlOutputBufferPtr output;
int level = 0;
int indent = 1;
const char *xencoding = NULL;
rb_scan_args(argc, argv, "01", &options);
if (!NIL_P(options))
{
VALUE rencoding, rindent, rlevel;
Check_Type(options, T_HASH);
rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding")));
rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent")));
rlevel = rb_hash_aref(options, ID2SYM(rb_intern("level")));
if (rindent == Qfalse)
indent = 0;
if (rlevel != Qnil)
level = NUM2INT(rlevel);
if (rencoding != Qnil)
{
xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding));
if (!xencoding)
rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding));
}
}
encodingHandler = xmlFindCharEncodingHandler(xencoding);
output = xmlAllocOutputBuffer(encodingHandler);
Data_Get_Struct(self, xmlNode, xnode);
xmlNodeDumpOutput(output, xnode->doc, xnode, level, indent, xencoding);
xmlOutputBufferFlush(output);
if (output->conv)
result = rb_str_new2((const char*) output->conv->content);
else
result = rb_str_new2((const char*) output->buffer->content);
xmlOutputBufferClose(output);
return result;
}
|
#xinclude_end? ⇒ Boolean
Specifies if this is an xinclude end node
294 295 296 |
# File 'lib/libxml/node.rb', line 294 def xinclude_end? node_type == XINCLUDE_END end |
#xinclude_start? ⇒ Boolean
Specifies if this is an xinclude start node
299 300 301 |
# File 'lib/libxml/node.rb', line 299 def xinclude_start? node_type == XINCLUDE_START end |
#xlink? ⇒ Boolean
Determine whether this node is an xlink node.
757 758 759 760 761 762 763 764 765 766 767 768 769 |
# File 'ext/libxml/ruby_xml_node.c', line 757
static VALUE rxml_node_xlink_q(VALUE self)
{
xmlNodePtr xnode;
xlinkType xlt;
Data_Get_Struct(self, xmlNode, xnode);
xlt = xlinkIsLink(xnode->doc, xnode);
if (xlt == XLINK_TYPE_NONE)
return (Qfalse);
else
return (Qtrue);
}
|
#xlink_type ⇒ Numeric
Obtain the type identifier for this xlink, if applicable. If this is not an xlink node (see xlink?
), will return nil.
779 780 781 782 783 784 785 786 787 788 789 790 791 |
# File 'ext/libxml/ruby_xml_node.c', line 779
static VALUE rxml_node_xlink_type(VALUE self)
{
xmlNodePtr xnode;
xlinkType xlt;
Data_Get_Struct(self, xmlNode, xnode);
xlt = xlinkIsLink(xnode->doc, xnode);
if (xlt == XLINK_TYPE_NONE)
return (Qnil);
else
return (INT2NUM(xlt));
}
|
#xlink_type_name ⇒ Object
Obtain the type name for this xlink, if applicable. If this is not an xlink node (see xlink?
), will return nil.
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 |
# File 'ext/libxml/ruby_xml_node.c', line 801
static VALUE rxml_node_xlink_type_name(VALUE self)
{
xmlNodePtr xnode;
xlinkType xlt;
Data_Get_Struct(self, xmlNode, xnode);
xlt = xlinkIsLink(xnode->doc, xnode);
switch (xlt)
{
case XLINK_TYPE_NONE:
return (Qnil);
case XLINK_TYPE_SIMPLE:
return (rb_str_new2("simple"));
case XLINK_TYPE_EXTENDED:
return (rb_str_new2("extended"));
case XLINK_TYPE_EXTENDED_SET:
return (rb_str_new2("extended_set"));
default:
rb_fatal("Unknowng xlink type, %d", xlt);
}
}
|