Ejemplo n.º 1
0
/*
 *  call-seq:
 *    attribute_nodes()
 *
 *  returns a list containing the Node attributes.
 */
static VALUE attribute_nodes(VALUE self)
{
    /* this code in the mode of xmlHasProp() */
    xmlNodePtr node ;
    VALUE attr ;

    attr = rb_ary_new() ;
    Data_Get_Struct(self, xmlNode, node);

    Nokogiri_xml_node_properties(node, attr);

    return attr ;
}
Ejemplo n.º 2
0
/*
 * call-seq:
 *   attribute_nodes
 *
 * Get a list of attributes for this Node
 */
static VALUE attribute_nodes(VALUE self)
{
  xmlTextReaderPtr reader;
  xmlNodePtr ptr;
  VALUE attr ;

  Data_Get_Struct(self, xmlTextReader, reader);

  attr = rb_ary_new() ;

  if (! has_attributes(reader))
    return attr ;

  ptr = xmlTextReaderExpand(reader);
  if(ptr == NULL) return Qnil;

  Nokogiri_xml_node_properties(ptr, attr);

  return attr ;
}
Ejemplo n.º 3
0
/*
 * call-seq:
 *   attribute_nodes
 *
 * Get a list of attributes for this Node
 */
static VALUE attribute_nodes(VALUE self)
{
  xmlTextReaderPtr reader;
  VALUE attr ;

  Data_Get_Struct(self, xmlTextReader, reader);

  attr = rb_ary_new() ;

  if (! has_attributes(reader))
    return attr ;

  xmlNodePtr ptr = xmlTextReaderExpand(reader);
  if(ptr == NULL) return Qnil;

  // FIXME I'm not sure if this is correct.....  I don't really like pointing
  // at this document, but I have to because of the assertions in
  // the node wrapping code.
  if(! DOC_RUBY_OBJECT_TEST(ptr->doc)) {
    VALUE rb_doc = Data_Wrap_Struct(cNokogiriXmlDocument, 0, 0, ptr->doc);
    ptr->doc->_private = malloc(sizeof(nokogiriTuple));
    rb_iv_set(rb_doc, "@decorators", Qnil);
    ((nokogiriTuplePtr)(ptr->doc->_private))->doc = (void *)rb_doc;
    ((nokogiriTuplePtr)(ptr->doc->_private))->unlinkedNodes = xmlXPathNodeSetCreate(NULL);
  }
  VALUE enc = rb_iv_get(self, "@encoding");

  if(enc != Qnil && NULL == ptr->doc->encoding) {
    ptr->doc->encoding = calloc((size_t)RSTRING_LEN(enc), sizeof(char));
    strncpy(
      (char *)ptr->doc->encoding,
      StringValuePtr(enc),
      (size_t)RSTRING_LEN(enc)
    );
  }

  Nokogiri_xml_node_properties(ptr, attr);

  return attr ;
}