本文整理汇总了C++中xmlSetGenericErrorFunc函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlSetGenericErrorFunc函数的具体用法?C++ xmlSetGenericErrorFunc怎么用?C++ xmlSetGenericErrorFunc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlSetGenericErrorFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s
//---------------------------------------------------------------------------
int Policy::import_schema_from_memory(const char* buffer, int len, const std::string& save_name)
{
if (!buffer || !len)
{
error = "The schema does not exist";
return -1;
}
Schema s(no_https);
xmlSetGenericErrorFunc(&s, &s.manage_generic_error);
xmlDocPtr doc = xmlParseMemory(buffer, len);
if (!doc)
{
// maybe put the errors from s.errors
error = "The schema given cannot be parsed";
xmlSetGenericErrorFunc(NULL, NULL);
return -1;
}
int ret = import_schema_from_doc(doc, save_name);
xmlFreeDoc(doc);
xmlSetGenericErrorFunc(NULL, NULL);
return ret;
}
示例2: initContext
xmlDoc *XMLDocument::readDocument(const std::string & xmlCode, const char * encoding, bool validate, std::string * error)
{
xmlParserCtxt *ctxt = initContext(error, validate);
xmlDoc *doc = 0;
int options = XML_PARSE_NSCLEAN | XML_PARSE_NOBLANKS;
if (validate)
{
options |= XML_PARSE_DTDVALID;
}
if (!ctxt)
{
xmlSetGenericErrorFunc(0, errorFunctionWithoutOutput);
return 0;
}
doc = xmlCtxtReadDoc(ctxt, (const xmlChar *)xmlCode.c_str(), 0, encoding, options);
if (!doc || !ctxt->valid)
{
*error = errorBuffer;
}
xmlSetGenericErrorFunc(0, errorFunctionWithoutOutput);
xmlFreeParserCtxt(ctxt);
return doc;
}
示例3: get_filter_from_xml
int get_filter_from_xml(const char *xml, struct acl_filter **filter)
{
xmlDoc *xmldoc = NULL;
int ret = 0;
if (xml == NULL || filter == NULL)
return 0;
xmlSetGenericErrorFunc(NULL, swallow_err_msg);
xmldoc = xmlParseMemory(xml, strlen(xml) + 1);
if (xmldoc == NULL)
goto err;
*filter = calloc(1, sizeof(**filter));
if (*filter == NULL)
goto err;
ret = parse_acl_filter(xmldoc->children, *filter);
if (ret == 0) {
free(*filter);
*filter = NULL;
}
err:
xmlSetGenericErrorFunc(NULL, NULL);
xmlFreeDoc(xmldoc);
return ret;
}
示例4: xmlSetGenericErrorFunc
void Skeleton::LoadSkeletonDataFromXml(const char* xmlData, size_t xmlLength, std::string& xmlErrors)
{
xmlDoc* doc = NULL;
try
{
xmlSetGenericErrorFunc(&xmlErrors, &errorHandler);
doc = xmlParseMemory(xmlData, (int)xmlLength);
if (doc)
{
xmlNode* root = xmlDocGetRootElement(doc);
LoadSkeletonData(root);
xmlFreeDoc(doc);
doc = NULL;
}
xmlSetGenericErrorFunc(NULL, NULL);
}
catch (const ColladaException&)
{
if (doc)
xmlFreeDoc(doc);
xmlSetGenericErrorFunc(NULL, NULL);
throw;
}
if (! xmlErrors.empty())
throw ColladaException("XML parsing failed");
}
示例5: startElementNs
ParseXML::ParseXML(void* session, startElementNsSAX2Func start)
: startElementNs(start)
, endElementNs(NULL)
, characters(NULL)
{
XmlError MyError;
MyError.Len = 0;
xmlSetGenericErrorFunc(&MyError, ErrorCallback);
xmlSAXHandler sax;
memset(&sax, 0, sizeof(sax));
sax.initialized = XML_SAX2_MAGIC;
sax.startElementNs = _start;
sax.endElementNs = _end;
sax.characters = _char;
mXmlContext = xmlCreatePushParserCtxt(&sax, this, NULL, 0, NULL);
if(mXmlContext == NULL)
{
xmlSetGenericErrorFunc(NULL, NULL);
throw std::runtime_error(MyError.Len != 0 ? MyError.Value : "XML Error");
}
curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, ParseHandler);
curl_easy_setopt(session, CURLOPT_WRITEDATA, this);
}
示例6: g_regex_new
/* str_unref() returned string */
static char *scrape_uri_from_lyricwiki_search_result(const char *buf, int64_t len)
{
xmlDocPtr doc;
gchar *uri = NULL;
/*
* workaround buggy lyricwiki search output where it cuts the lyrics
* halfway through the UTF-8 symbol resulting in invalid XML.
*/
GRegex *reg;
reg = g_regex_new("<(lyrics?)>.*</\\1>", (G_REGEX_MULTILINE | G_REGEX_DOTALL | G_REGEX_UNGREEDY), 0, NULL);
gchar *newbuf = g_regex_replace_literal(reg, buf, len, 0, "", G_REGEX_MATCH_NEWLINE_ANY, NULL);
g_regex_unref(reg);
/*
* temporarily set our error-handling functor to our suppression function,
* but we have to set it back because other components of Audacious depend
* on libxml and we don't want to step on their code paths.
*
* unfortunately, libxml is anti-social and provides us with no way to get
* the previous error functor, so we just have to set it back to default after
* parsing and hope for the best.
*/
xmlSetGenericErrorFunc(NULL, libxml_error_handler);
doc = xmlParseMemory(newbuf, strlen(newbuf));
xmlSetGenericErrorFunc(NULL, NULL);
if (doc != NULL)
{
xmlNodePtr root, cur;
root = xmlDocGetRootElement(doc);
for (cur = root->xmlChildrenNode; cur; cur = cur->next)
{
if (xmlStrEqual(cur->name, (xmlChar *) "url"))
{
xmlChar *lyric;
gchar *basename;
lyric = xmlNodeGetContent(cur);
basename = g_path_get_basename((gchar *) lyric);
uri = str_printf("http://lyrics.wikia.com/index.php?action=edit"
"&title=%s", basename);
g_free(basename);
xmlFree(lyric);
}
}
xmlFreeDoc(doc);
}
g_free(newbuf);
return uri;
}
示例7: docLoaderFunc
static xmlDocPtr docLoaderFunc(const xmlChar* uri,
xmlDictPtr,
int options,
void* ctxt,
xsltLoadType type)
{
if (!globalProcessor)
return 0;
switch (type) {
case XSLT_LOAD_DOCUMENT: {
xsltTransformContextPtr context = (xsltTransformContextPtr)ctxt;
xmlChar* base = xmlNodeGetBase(context->document->doc, context->node);
URL url(URL(ParsedURLString, reinterpret_cast<const char*>(base)), reinterpret_cast<const char*>(uri));
xmlFree(base);
ResourceError error;
ResourceResponse response;
Vector<char> data;
bool requestAllowed = globalCachedResourceLoader->frame() && globalCachedResourceLoader->document()->securityOrigin()->canRequest(url);
if (requestAllowed) {
globalCachedResourceLoader->frame()->loader().loadResourceSynchronously(url, AllowStoredCredentials, DoNotAskClientForCrossOriginCredentials, error, response, data);
if (error.isNull())
requestAllowed = globalCachedResourceLoader->document()->securityOrigin()->canRequest(response.url());
else
data.clear();
}
if (!requestAllowed) {
data.clear();
globalCachedResourceLoader->printAccessDeniedMessage(url);
}
PageConsole* console = 0;
Frame* frame = globalProcessor->xslStylesheet()->ownerDocument()->frame();
if (frame && frame->page())
console = &frame->page()->console();
xmlSetStructuredErrorFunc(console, XSLTProcessor::parseErrorFunc);
xmlSetGenericErrorFunc(console, XSLTProcessor::genericErrorFunc);
// We don't specify an encoding here. Neither Gecko nor WinIE respects
// the encoding specified in the HTTP headers.
xmlDocPtr doc = xmlReadMemory(data.data(), data.size(), (const char*)uri, 0, options);
xmlSetStructuredErrorFunc(0, 0);
xmlSetGenericErrorFunc(0, 0);
return doc;
}
case XSLT_LOAD_STYLESHEET:
return globalProcessor->xslStylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
default:
break;
}
return 0;
}
示例8: transform
/*
* call-seq:
* transform(document, params = [])
*
* Apply an XSLT stylesheet to an XML::Document.
* +params+ is an array of strings used as XSLT parameters.
* returns Nokogiri::XML::Document
*
* Example:
*
* doc = Nokogiri::XML(File.read(ARGV[0]))
* xslt = Nokogiri::XSLT(File.read(ARGV[1]))
* puts xslt.transform(doc, ['key', 'value'])
*
*/
static VALUE transform(int argc, VALUE* argv, VALUE self)
{
VALUE xmldoc, paramobj, errstr, exception ;
xmlDocPtr xml ;
xmlDocPtr result ;
nokogiriXsltStylesheetTuple *wrapper;
const char** params ;
long param_len, j ;
int parse_error_occurred ;
rb_scan_args(argc, argv, "11", &xmldoc, ¶mobj);
if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0L) ; }
if (!rb_obj_is_kind_of(xmldoc, cNokogiriXmlDocument))
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::Document");
/* handle hashes as arguments. */
if(T_HASH == TYPE(paramobj)) {
paramobj = rb_funcall(paramobj, rb_intern("to_a"), 0);
paramobj = rb_funcall(paramobj, rb_intern("flatten"), 0);
}
Check_Type(paramobj, T_ARRAY);
Data_Get_Struct(xmldoc, xmlDoc, xml);
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
param_len = RARRAY_LEN(paramobj);
params = calloc((size_t)param_len+1, sizeof(char*));
for (j = 0 ; j < param_len ; j++) {
VALUE entry = rb_ary_entry(paramobj, j);
const char * ptr = StringValuePtr(entry);
params[j] = ptr;
}
params[param_len] = 0 ;
errstr = rb_str_new(0, 0);
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
xmlSetGenericErrorFunc(NULL, (xmlGenericErrorFunc)&swallow_superfluous_xml_errors);
result = xsltApplyStylesheet(wrapper->ss, xml, params);
free(params);
xsltSetGenericErrorFunc(NULL, NULL);
xmlSetGenericErrorFunc(NULL, NULL);
parse_error_occurred = (Qfalse == rb_funcall(errstr, rb_intern("empty?"), 0));
if (parse_error_occurred) {
exception = rb_exc_new3(rb_eRuntimeError, errstr);
rb_exc_raise(exception);
}
return Nokogiri_wrap_xml_document((VALUE)0, result) ;
}
示例9: setLoaderForLibXMLCallbacks
bool XSLStyleSheet::parseString(const String& string, bool)
{
// Parse in a single chunk into an xmlDocPtr
const UChar BOM = 0xFEFF;
const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
setLoaderForLibXMLCallbacks(docLoader());
if (!m_stylesheetDocTaken)
xmlFreeDoc(m_stylesheetDoc);
m_stylesheetDocTaken = false;
#if ENABLE(INSPECTOR)
Console* console = 0;
if (Frame* frame = ownerDocument()->frame())
console = frame->domWindow()->console();
xmlSetStructuredErrorFunc(console, XSLTProcessor::parseErrorFunc);
xmlSetGenericErrorFunc(console, XSLTProcessor::genericErrorFunc);
#endif
const char* buffer = reinterpret_cast<const char*>(string.characters());
int size = string.length() * sizeof(UChar);
xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(buffer, size);
if (m_parentStyleSheet) {
// The XSL transform may leave the newly-transformed document
// with references to the symbol dictionaries of the style sheet
// and any of its children. XML document disposal can corrupt memory
// if a document uses more than one symbol dictionary, so we
// ensure that all child stylesheets use the same dictionaries as their
// parents.
xmlDictFree(ctxt->dict);
ctxt->dict = m_parentStyleSheet->m_stylesheetDoc->dict;
xmlDictReference(ctxt->dict);
}
m_stylesheetDoc = xmlCtxtReadMemory(ctxt, buffer, size,
href().utf8().data(),
BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE",
XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_NOWARNING | XML_PARSE_NOCDATA);
xmlFreeParserCtxt(ctxt);
loadChildSheets();
xmlSetStructuredErrorFunc(0, 0);
xmlSetGenericErrorFunc(0, 0);
setLoaderForLibXMLCallbacks(0);
return m_stylesheetDoc;
}
示例10: docLoaderFunc
static xmlDocPtr docLoaderFunc(const xmlChar* uri,
xmlDictPtr,
int options,
void* ctxt,
xsltLoadType type)
{
if (!globalProcessor)
return 0;
switch (type) {
case XSLT_LOAD_DOCUMENT: {
xsltTransformContextPtr context = (xsltTransformContextPtr)ctxt;
xmlChar* base = xmlNodeGetBase(context->document->doc, context->node);
KURL url(KURL(ParsedURLString, reinterpret_cast<const char*>(base)), reinterpret_cast<const char*>(uri));
xmlFree(base);
ResourceLoaderOptions fetchOptions(ResourceFetcher::defaultResourceOptions());
FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames::xml, fetchOptions);
request.setOriginRestriction(FetchRequest::RestrictToSameOrigin);
ResourcePtr<Resource> resource = globalResourceFetcher->fetchSynchronously(request);
if (!resource || !globalProcessor)
return 0;
PageConsole* console = 0;
Frame* frame = globalProcessor->xslStylesheet()->ownerDocument()->frame();
if (frame && frame->page())
console = &frame->page()->console();
xmlSetStructuredErrorFunc(console, XSLTProcessor::parseErrorFunc);
xmlSetGenericErrorFunc(console, XSLTProcessor::genericErrorFunc);
// We don't specify an encoding here. Neither Gecko nor WinIE respects
// the encoding specified in the HTTP headers.
SharedBuffer* data = resource->resourceBuffer();
xmlDocPtr doc = data ? xmlReadMemory(data->data(), data->size(), (const char*)uri, 0, options) : 0;
xmlSetStructuredErrorFunc(0, 0);
xmlSetGenericErrorFunc(0, 0);
return doc;
}
case XSLT_LOAD_STYLESHEET:
return globalProcessor->xslStylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
default:
break;
}
return 0;
}
示例11: init
int init(void)
{
daemonize = TRUE;
every = EVERY_5SECS;
xmlSetGenericErrorFunc(NULL, UpwatchXmlGenericErrorFunc);
return(1);
}
示例12: lpc2xml_convert_string
int lpc2xml_convert_string(lpc2xml_context* context, char **content) {
int ret = -1;
xmlBufferPtr buffer = xmlBufferCreate();
xmlSaveCtxtPtr save_ctx;
lpc2xml_context_clear_logs(context);
xmlSetGenericErrorFunc(context, lpc2xml_genericxml_error);
save_ctx = xmlSaveToBuffer(buffer, "UTF-8", XML_SAVE_FORMAT);
if(save_ctx != NULL) {
ret = internal_convert_lpc2xml(context);
if(ret == 0) {
ret = xmlSaveDoc(save_ctx, context->doc);
if(ret != 0) {
lpc2xml_log(context, LPC2XML_ERROR, "Can't save document");
lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
}
}
xmlSaveClose(save_ctx);
} else {
lpc2xml_log(context, LPC2XML_ERROR, "Can't initialize internal buffer");
lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
}
if(ret == 0) {
#if LIBXML_VERSION >= 20800
*content = (char *)xmlBufferDetach(buffer);
#else
*content = strdup((const char *)xmlBufferContent(buffer));
#endif
}
xmlBufferFree(buffer);
return ret;
}
示例13: initXML
XMLParser::XMLParser(Common::ReadStream &stream, bool makeLower, const Common::UString &fileName) {
initXML();
Common::UString parseError;
xmlSetGenericErrorFunc(static_cast<void *>(&parseError), errorFuncUString);
const int options = XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS | XML_PARSE_NONET |
XML_PARSE_NSCLEAN | XML_PARSE_NOCDATA;
xmlDocPtr xml = xmlReadIO(readStream, closeStream, static_cast<void *>(&stream),
fileName.c_str(), 0, options);
if (!xml) {
Common::Exception e;
if (!parseError.empty())
e.add("%s", parseError.c_str());
e.add("XML document failed to parse");
throw e;
}
BOOST_SCOPE_EXIT( (&xml) ) {
xmlFreeDoc(xml);
} BOOST_SCOPE_EXIT_END
xmlNodePtr root = xmlDocGetRootElement(xml);
if (!root)
throw Common::Exception("XML document has no root node");
_rootNode.reset(new XMLNode(*root, makeLower));
deinitXML();
}
示例14: irislwz_Validate
int irislwz_Validate(IRISLWZ_HANDLE *handle, const char *xml, char **beautified)
/*!\brief Do an XML validation against a text
*
* This function takes the given \p xml test an tries to validate it with the XML
* library (xmlReadMemory). If the XML is valid, a \p beautified version, which can
* be better read by humans, can be stored optionally.
*
* \param[in] handle pointer to an IRISLWZ_HANDLE object
* \param[in] xml pointer to the text which should be validated
* \param[out] beautified optional pointer to which a beautified version of the xml
* is written. The Memory for this is allocated by the library, but must be freed by the
* client using \p free.
*
* \returns If the XML is valid, the function returns 1, otherwise 0.
*
* \example
\code
const char *xml="<iris1:request xmlns:iris1=\"urn:ietf:params:xml:ns:iris1\">"
"<iris1:searchSet><iris1:lookupEntity registryType=\"dchk1\" "
"entityClass=\"domain-name\" entityName=\"denic.de\"/>"
"</iris1:searchSet></iris1:request>";
char *beautified=NULL;
if (irislwz_Validate(handle,xml,&beautified)) {
printf ("Original XML code:\n");
printf ("%s\n",xml);
printf ("Beautified version:\n");
printf ("%s\n",beautified);
}
if (beautified) free(beautified);
\endcode
*
* \ingroup DCHK_API_IRISLWZ
*/
{
xmlSetGenericErrorFunc(handle,irislwz_xmlGenericErrorFunc);
xmlDoc *doc = NULL;
//xmlNode *root_element = NULL;
int size=(int)strlen(xml);
//printf ("Query: >>%s<<\n",xml);
//printf ("Size: %i Bytes\n",size);
doc = xmlReadMemory (xml, size,
NULL,
"UTF-8",
XML_PARSE_NONET);
if (doc == NULL) {
irislwz_SetError(handle,74044,NULL);
return 0;
}
if (beautified) {
xmlChar *mem;
int size;
xmlKeepBlanksDefault(0);
xmlDocDumpFormatMemoryEnc(doc, &mem, &size, handle->localcharset,1);
*beautified=strdup((char*)mem);
xmlFree(mem);
}
xmlFreeDoc(doc);
return 1;
}
示例15: init_libxml2
// [[Rcpp::export]]
void init_libxml2() {
// Check that header and libs are compatible
LIBXML_TEST_VERSION
xmlInitParser();
xmlSetStructuredErrorFunc(NULL, handleStructuredError);
xmlSetGenericErrorFunc(NULL, handleGenericError);
}