Class: LibXML::XML::Namespace
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
Enumerable,
Comparable
|
|
| Inherits: | Object |
| Defined in: | ext/libxml/ruby_xml_namespace.c, lib/libxml/namespace.rb |
Class Method Summary
-
.new(node, "prefix", "href") ⇒ Namespace
constructor
Create a new namespace and adds it to the specified node.
Instance Method Summary
-
#<=>(namespace2)
Compares two namespace objects.
-
#each {|ns| ... }
libxml stores namespaces in memory as a linked list.
-
#href ⇒ "href"
Usage:
-
#next ⇒ Namespace
Obtain the next namespace.
-
#node_type ⇒ Numeric
Obtain this namespace’s type identifier.
-
#prefix ⇒ "prefix"
Obtain the namespace’s prefix.
-
#to_s ⇒ "string"
Returns the string represenation of a namespace.
Constructor Details
.new(node, "prefix", "href") ⇒ Namespace
Create a new namespace and adds it to the specified node. Note this does not assign the node to the namespace. To do that see the Namespaces#namespace method.
# File 'ext/libxml/ruby_xml_namespace.c', line 51
static VALUE rxml_namespace_initialize(VALUE self, VALUE node, VALUE prefix,
VALUE href)
{
xmlNodePtr xnode;
xmlChar *xmlPrefix;
xmlNsPtr xns;
TypedData_Get_Struct(node, xmlNode, &rxml_node_data_type, xnode);
xmlResetLastError();
/* Prefix can be null - that means its the default namespace */
xmlPrefix = NIL_P(prefix) ? NULL : (xmlChar *)StringValuePtr(prefix);
xns = xmlNewNs(xnode, (xmlChar*) StringValuePtr(href), xmlPrefix);
RTYPEDDATA_DATA(self) = xns;
return self;
}
Instance Method Details
#<=>(namespace2)
Compares two namespace objects. Namespace objects are considered equal if their prefixes and hrefs are the same.
#each {|ns| ... }
libxml stores namespaces in memory as a linked list. Use the each method to iterate over the list. Note the first namespace in the loop is the current namespace.
Usage:
namespace.each do |ns|
#..
end
# File 'lib/libxml/namespace.rb', line 37
def each ns = self while ns yield ns ns = ns.next end end
#href ⇒ "href"
# File 'ext/libxml/ruby_xml_namespace.c', line 79
static VALUE rxml_namespace_href_get(VALUE self)
{
xmlNsPtr xns;
TypedData_Get_Struct(self, xmlNs, &rxml_namespace_type, xns);
if (xns->href == NULL)
return Qnil;
else
return rxml_new_cstr( xns->href, NULL);
}
#next ⇒ Namespace
# File 'ext/libxml/ruby_xml_namespace.c', line 136
static VALUE rxml_namespace_next(VALUE self)
{
xmlNsPtr xns;
TypedData_Get_Struct(self, xmlNs, &rxml_namespace_type, xns);
/* Guard against libxml2's XPath hack where xns->next stores a parent
element pointer instead of the next namespace (see xmlXPathNodeSetAddNs
in xpath.c). xmlNs.type and xmlNode.type share the same struct offset,
so checking the type is safe even when next points to an xmlNode. */
if (xns == NULL || xns->next == NULL || xns->next->type != XML_LOCAL_NAMESPACE)
return (Qnil);
return rxml_namespace_wrap(xns->next);
}
#node_type ⇒ Numeric
Obtain this namespace’s type identifier.
# File 'ext/libxml/ruby_xml_namespace.c', line 95
static VALUE rxml_namespace_node_type(VALUE self)
{
xmlNsPtr xns;
TypedData_Get_Struct(self, xmlNs, &rxml_namespace_type, xns);
return INT2NUM(xns->type);
}
#prefix ⇒ "prefix"
# File 'ext/libxml/ruby_xml_namespace.c', line 114
static VALUE rxml_namespace_prefix_get(VALUE self)
{
xmlNsPtr xns;
TypedData_Get_Struct(self, xmlNs, &rxml_namespace_type, xns);
if (xns->prefix == NULL)
return Qnil;
else
return rxml_new_cstr( xns->prefix, NULL);
}
#to_s ⇒ "string"
Returns the string represenation of a namespace.
Usage:
namespace.to_s