Exemple #1
0
/*
 * call-seq:
 *   attribute(name)
 *
 * Get the value of attribute named +name+
 */
static VALUE reader_attribute(VALUE self, VALUE name)
{
  xmlTextReaderPtr reader;
  xmlChar *value ;
  Data_Get_Struct(self, xmlTextReader, reader);

  if(name == Qnil) return Qnil;
  name = StringValue(name) ;

  value = xmlTextReaderGetAttribute(reader, (xmlChar*)StringValuePtr(name));
  if(value == NULL) {
    /* this section is an attempt to workaround older versions of libxml that
       don't handle namespaces properly in all attribute-and-friends functions */
    xmlChar *prefix = NULL ;
    xmlChar *localname = xmlSplitQName2((xmlChar*)StringValuePtr(name), &prefix);
    if (localname != NULL) {
      value = xmlTextReaderLookupNamespace(reader, localname);
      xmlFree(localname) ;
    } else {
      value = xmlTextReaderLookupNamespace(reader, prefix);
    }
    xmlFree(prefix);
  }
  if(value == NULL) return Qnil;

  VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
  VALUE rb_value = NOKOGIRI_STR_NEW2(value,
      RTEST(enc) ? StringValuePtr(enc) : NULL);
  xmlFree(value);
  return rb_value;
}
Exemple #2
0
/* @method String XmlReader.lookupNameSpace(String ns) */
METHOD XmlReader_lookupNameSpace(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlTextReaderPtr reader = (xmlTextReaderPtr) p_cptr(sfp[0]);
    xmlChar* ns   = (xmlChar*) p_char(sfp[1]);
    char* ret = (char*) xmlTextReaderLookupNamespace(reader,ns);
    KNH_RETURN(ctx,sfp,new_String(ctx,B(ret),NULL));
}
Exemple #3
0
//## @Native String XmlReader.lookupNameSpace(String ns);
static KMETHOD XmlReader_lookupNameSpace(KonohaContext *kctx, KonohaStack *sfp)
{
	xmlTextReaderPtr reader = getRawXmlReader(sfp[0]);
	xmlChar* ns = (xmlChar *)kString_text(sfp[1].asString);
	char* ret = (reader != NULL) ? (char *) xmlTextReaderLookupNamespace(reader,ns) : NULL;
	KReturn(KLIB new_kString(kctx, GcUnsafe, ret, strlen(ret), 0));
}
Exemple #4
0
/*
 * call-seq:
 *    reader.lookup_namespace(prefix) -> value
 *
 * Resolve a namespace prefix in the scope of the current element.
 * To return the default namespace, specify nil as +prefix+.
 */
static VALUE rxml_reader_lookup_namespace(VALUE self, VALUE prefix)
{
  VALUE result = Qnil;
  xmlTextReaderPtr xReader = rxml_text_reader_get(self);
  const xmlChar *xnamespace = xmlTextReaderLookupNamespace(xReader, (const xmlChar *) StringValueCStr(prefix));
  const xmlChar *xencoding = xmlTextReaderConstEncoding(xReader);

  if (xnamespace)
  {
    result = rxml_new_cstr((const char*)xnamespace, (const char*)xencoding);
    xmlFree((void *)xnamespace);
  }
  return result;
}
Exemple #5
0
/* reader:lookup_namespace() */
static int xmlreader_lookup_namespace(lua_State *L) {
  xmlreader xr = check_xmlreader(L, 1);

  char *ret = (char*)xmlTextReaderLookupNamespace(xr, (xmlChar*)luaL_checkstring(L, 2));
  if (ret) {
    lua_pushstring(L, ret);
    xmlFree(ret);
    return 1;
  } else {
    lua_pushnil(L);
    xmlreader_pusherror(L);
    return 2;
  }
}
Exemple #6
0
/*
 * call-seq:
 *    reader.lookup_namespace(prefix) -> value
 *
 * Resolve a namespace prefix in the scope of the current element.
 * To return the default namespace, specify nil as +prefix+.
 */
static VALUE rxml_reader_lookup_namespace(VALUE self, VALUE prefix)
{
  const xmlChar *result = xmlTextReaderLookupNamespace(rxml_text_reader_get(
      self), (const xmlChar *) StringValueCStr(prefix));
  return (result == NULL ? Qnil : rb_str_new2((const char*)result));
}