Sha256: 9afdd665f3643ecfd9a3d73d02fe78c360022da4b32979d38118e9fab76b5e97

Contents?: true

Size: 1.66 KB

Versions: 89

Compression:

Stored size: 1.66 KB

Contents

#include <xml_namespace.h>

VALUE cNokogiriXmlNamespace ;

/*
 * call-seq:
 *  prefix
 *
 * Get the prefix for this namespace.  Returns +nil+ if there is no prefix.
 */
static VALUE prefix(VALUE self)
{
  xmlNsPtr ns;
  xmlDocPtr doc;

  Data_Get_Struct(self, xmlNs, ns);
  if(!ns->prefix) return Qnil;

  Data_Get_Struct(rb_iv_get(self, "@document"), xmlDoc, doc);

  return NOKOGIRI_STR_NEW2(ns->prefix);
}

/*
 * call-seq:
 *  href
 *
 * Get the href for this namespace
 */
static VALUE href(VALUE self)
{
  xmlNsPtr ns;
  xmlDocPtr doc;

  Data_Get_Struct(self, xmlNs, ns);
  if(!ns->href) return Qnil;

  Data_Get_Struct(rb_iv_get(self, "@document"), xmlDoc, doc);

  return NOKOGIRI_STR_NEW2(ns->href);
}

VALUE Nokogiri_wrap_xml_namespace(xmlDocPtr doc, xmlNsPtr node)
{
  VALUE ns, document, node_cache;

  assert(doc->_private);

  if(node->_private)
    return (VALUE)node->_private;

  ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, node);

  document = DOC_RUBY_OBJECT(doc);

  node_cache = rb_iv_get(document, "@node_cache");
  rb_ary_push(node_cache, ns);

  rb_iv_set(ns, "@document", DOC_RUBY_OBJECT(doc));

  node->_private = (void *)ns;

  return ns;
}

VALUE Nokogiri_wrap_xml_namespace2(VALUE document, xmlNsPtr node)
{
  xmlDocPtr doc;
  Data_Get_Struct(document, xmlDoc, doc) ;
  return Nokogiri_wrap_xml_namespace(doc, node);
}


void init_xml_namespace()
{
  VALUE nokogiri  = rb_define_module("Nokogiri");
  VALUE xml       = rb_define_module_under(nokogiri, "XML");
  VALUE klass     = rb_define_class_under(xml, "Namespace", rb_cObject);

  cNokogiriXmlNamespace = klass;

  rb_define_method(klass, "prefix", prefix, 0);
  rb_define_method(klass, "href", href, 0);
}

Version data entries

89 entries across 89 versions & 13 rubygems

Version Path
nokogiri-maglev--1.5.2 ext/nokogiri/xml_namespace.c
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
ftl-0.2.0 vendor/bundle/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
horseman-0.0.5 vendor/ruby/1.9.1/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/ext/nokogiri/xml_namespace.c
nokogiri-1.5.3.rc3-x86-mswin32-60 ext/nokogiri/xml_namespace.c
nokogiri-1.5.3.rc3-x86-mingw32 ext/nokogiri/xml_namespace.c
nokogiri-1.5.3.rc3-java ext/nokogiri/xml_namespace.c
nokogiri-1.5.3.rc3 ext/nokogiri/xml_namespace.c
nokogiri-1.5.3.rc2-java ext/nokogiri/xml_namespace.c
nokogiri-1.5.3.rc2-x86-mingw32 ext/nokogiri/xml_namespace.c
nokogiri-1.5.3.rc2-x86-mswin32-60 ext/nokogiri/xml_namespace.c