/* * call-seq: * reader.namespace_uri -> URI * * Determine the namespace URI of the node. */ static VALUE rxml_reader_namespace_uri(VALUE self) { xmlTextReaderPtr xReader = rxml_text_reader_get(self); const xmlChar *result = xmlTextReaderConstNamespaceUri(xReader); const xmlChar *xencoding = xmlTextReaderConstEncoding(xReader); return (result == NULL ? Qnil : rxml_new_cstr(result, xencoding)); }
/* * call-seq: * reader.xml_version -> version * * Determine the XML version of the document being read. */ static VALUE rxml_reader_xml_version(VALUE self) { xmlTextReaderPtr xReader = rxml_text_reader_get(self); const xmlChar *result = xmlTextReaderConstXmlVersion(xReader); const xmlChar *xencoding = xmlTextReaderConstEncoding(xReader); return (result == NULL ? Qnil : rxml_new_cstr(result, xencoding)); }
/* * call-seq: * reader.xml_lang -> value * * Get the xml:lang scope within which the node resides. */ static VALUE rxml_reader_xml_lang(VALUE self) { xmlTextReaderPtr xReader = rxml_text_reader_get(self); const xmlChar *result = xmlTextReaderConstXmlLang(xReader); const xmlChar *xencoding = xmlTextReaderConstEncoding(xReader); return (result == NULL ? Qnil : rxml_str_new2(result, xencoding)); }
/* * call-seq: * reader.encoding -> XML::Encoding::UTF_8 * * Returns the encoding of the document being read. Note you * first have to read data from the reader for encoding * to return a value * * reader = XML::Reader.file(XML_FILE) * assert_nil(reader.encoding) * reader.read * assert_equal(XML::Encoding::UTF_8, reader.encoding) * * In addition, libxml always appears to return nil for the encoding * when parsing strings. */ static VALUE rxml_reader_encoding(VALUE self) { xmlTextReaderPtr xreader = rxml_text_reader_get(self); const xmlChar *xencoding = xmlTextReaderConstEncoding(xreader); if (xencoding) return INT2NUM(xmlParseCharEncoding(xencoding)); else return INT2NUM(XML_CHAR_ENCODING_NONE); }
/* reader:encoding() */ static int xmlreader_encoding(lua_State *L) { xmlreader xr = check_xmlreader(L, 1); const char *enc = (char*)xmlTextReaderConstEncoding(xr); if (enc) { lua_pushstring(L, enc); return 1; } else { lua_pushnil(L); xmlreader_pusherror(L); return 2; } }
/** * Start parsing an XML stream by checking the encoding and version. */ int _xml_parser_init(xmlTextReaderPtr reader, const char *top_name, int *idx_version, int min_version, int max_version) { const char *name, *encoding; char *value; int type, ver; if (xml_next_tag(reader, "", &name, &type) < 0) return -1; if (strcmp(name, top_name)) { ltfsmsg(LTFS_ERR, "17017E", name); return -1; } /* reject this XML file if it isn't UTF-8 */ encoding = (const char *)xmlTextReaderConstEncoding(reader); if (! encoding || strcmp(encoding, "UTF-8")) { ltfsmsg(LTFS_ERR, "17018E", encoding); return -1; } /* check the version attribute of the top-level tag */ value = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "version"); if (! value) { ltfsmsg(LTFS_ERR, "17019E"); return -1; } if (_xml_parse_version(value, &ver) < 0) { ltfsmsg(LTFS_ERR, "17020E", value); return -LTFS_UNSUPPORTED_INDEX_VERSION; } if (ver < min_version || ver > max_version) { ltfsmsg(LTFS_ERR, "17021E", top_name, value); free(value); return -LTFS_UNSUPPORTED_INDEX_VERSION; } *idx_version = ver; /* * OSR * * This allocation must be freed with xmlFree * */ #ifndef HP_mingw_BUILD free(value); #else xmlFree(value); #endif return 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; }
/* * call-seq: * reader.read_string -> string * * Read the contents of an element or a text node as a string. * * Return a string containing the contents of the Element or Text node, or nil * if the reader is positioned on any other type of node. */ static VALUE rxml_reader_read_string(VALUE self) { VALUE result = Qnil; xmlTextReaderPtr xReader = rxml_text_reader_get(self); xmlChar *xml = xmlTextReaderReadString(xReader); if (xml) { const xmlChar *xencoding = xmlTextReaderConstEncoding(xReader); result = rxml_new_cstr((const char*) xml, xencoding); xmlFree(xml); } return result; }
/* * call-seq: * reader[key] -> value * * Provide the value of the attribute with the specified index (if +key+ is an * integer) or with the specified name (if +key+ is a string) relative to the * containing element, as a string. */ static VALUE rxml_reader_attribute(VALUE self, VALUE key) { VALUE result = Qnil; xmlChar *xattr; xmlTextReaderPtr xReader = rxml_text_reader_get(self); const xmlChar *xencoding = xmlTextReaderConstEncoding(xReader); if (TYPE(key) == T_FIXNUM) { xattr = xmlTextReaderGetAttributeNo(xReader, FIX2INT(key)); } else { xattr = xmlTextReaderGetAttribute(xReader, (const xmlChar *) StringValueCStr(key)); } if (xattr) { result = rxml_new_cstr(xattr, xencoding); xmlFree(xattr); } return result; }
/* @method String XmlReader.constEncoding() */ METHOD XmlReader_constEncoding(Ctx *ctx, knh_sfp_t *sfp) { xmlTextReaderPtr reader = (xmlTextReaderPtr) p_cptr(sfp[0]); char* ret = (char*)xmlTextReaderConstEncoding(reader); KNH_RETURN(ctx,sfp,new_String(ctx,B(ret),NULL)); }
//## @Native String XmlReader.constEncoding(); static KMETHOD XmlReader_constEncoding(KonohaContext *kctx, KonohaStack *sfp) { xmlTextReaderPtr reader = getRawXmlReader(sfp[0]); char* ret = (reader != NULL) ? (char *)xmlTextReaderConstEncoding(reader) : NULL; KReturn(KLIB new_kString(kctx, GcUnsafe, ret, strlen(ret), 0)); }