Home > libxml2 error > libxml2 error

Libxml2 Error

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the libxml error codes company Business Learn more about hiring developers or posting ads with us Stack Overflow initgenericerrordefaultfunc Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 libxml2 xmlsetgenericerrorfunc million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up libxml2 error handling up vote 0 down vote favorite I'm writing a small wrapper around libxml2 in C++, and libxml_get_errors I'm trying to work out how to handle errors. For now, let's say I just want to print them out. Here's what I've got at present: My error handling function: void foo(void *ctx, const char *msg, ...) { cout << msg << endl; return; } Initialised like this: xmlGenericErrorFunc handler = (xmlGenericErrorFunc)foo; initGenericErrorDefaultFunc(&handler); However, if I parse a bad XPath, I get this output: %s Without the error handling code, I get this:

Xmlsetgenericerrorfunc Example

XPath error : Invalid expression //.@foobar ^ Obviously eventually my error handling will do more than just print out the error message (it'll log it to a database or something), but for now - how can I get that error string? c++ c libxml2 share|improve this question asked Nov 5 '09 at 9:57 Dominic Rodger 60.8k13154180 add a comment| 2 Answers 2 active oldest votes up vote 4 down vote accepted The three dots at the end of the argument list for you function foo() means it takes a variable amount of arguments. To be able to print those you could do something like this (not tested): #include #define TMP_BUF_SIZE 256 void foo(void *ctx, const char *msg, ...) { char string[TMP_BUF_SIZE]; va_list arg_ptr; va_start(arg_ptr, msg); vsnprintf(string, TMP_BUF_SIZE, msg, arg_ptr); va_end(arg_ptr); cout << string << endl; return; } share|improve this answer answered Nov 5 '09 at 10:17 Puppe 3,1901525 That's nearly there - it gets me "Invalid expression", but not the rest. –Dominic Rodger Nov 5 '09 at 10:57 That's probably all the message contains, you said you got %s when you only printed msg, that indicates that there is only one more argument given to foo() and that's a string to be printed. Maybe the information here can help you? xmlsoft.org/html/libxml-xmlerror.html#xmlGenericErrorFun

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site

Xmlschemasetparsererrors

About Us Learn more about Stack Overflow the company Business Learn more about xmlgenericerrorfunc hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss libxml2 xmlreadmemory Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up how to get off http://stackoverflow.com/questions/1679515/libxml2-error-handling with the libxml2 error messages up vote 0 down vote favorite I want to use the libxml2 lib to parse my xml files. Now, when I have some bad xml file the lib itself is printing large error messages. below is some sample code reader = xmlReaderForFile(filename, NULL, 0); if (reader != NULL) { ret = xmlTextReaderRead(reader); while (ret == 1) { printf("_________________________________\n"); processNode(reader); ret http://stackoverflow.com/questions/10189085/how-to-get-off-with-the-libxml2-error-messages = xmlTextReaderRead(reader); printf("_________________________________\n"); } xmlFreeTextReader(reader); if (ret != 0) { fprintf(stderr, "%s : failed to parse\n", filename); } } In above example, if I have bad xml file, I get error like this my.xml:4: parser error : attributes construct error include type="text"this is text. this might be excluded in the next occurrence my.xml:4: parser error : Couldn't find end of Start Tag include include type="text"this is text. this might be excluded in the next occurrence my.xml : failed to parse Instead, I just want to return some error no. and get off with this ugly lib messages. what do I do ? c xml xml-parsing share|improve this question edited Apr 17 '12 at 10:03 CharlesB 42.4k11117137 asked Apr 17 '12 at 10:00 JohnG 182414 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted The last parameter to xmlReaderForFile(filename, NULL, 0); is a set of option flags. Reading the documentation for these flags, I see there are two options you might want to set: XML_PARSE_NOERROR and XML_PARSE_NOWARNING. Note that I haven't tried any of this, I just Googled libxml2 and xmlReaderForFile. You will need to or the fla

here for a quick overview of the site Help Center Detailed answers to any questions you might http://stackoverflow.com/questions/12107423/libxml2-get-validation-errors have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads https://github.com/trevorlinton/libxml2/blob/master/error.c with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million libxml2 error programmers, just like you, helping each other. Join them; it only takes a minute: Sign up libxml2 get validation errors up vote 2 down vote favorite 1 I am using libxml2 to validate an xml file against an xsd schema. Using xmlSchemaSetParserErrors function, errors are output to stderr. I need to get these validation errors, libxml error codes store them in memory and display to the user. How can I redirect these errors ? Could you provide me some examples ? Thanks, Andrea c++ libxml2 share|improve this question asked Aug 24 '12 at 10:14 Andrea Caloni 365 Unless I'm missing something, xmlSchemaSetParserErrors() can be used to set your own callback for errors. So, where's the problem, sir? –MichaƂ Górny Aug 24 '12 at 10:57 There is no problem, I was just looking for an example about how to setup a custom callback for errors. –Andrea Caloni Aug 27 '12 at 9:03 add a comment| 3 Answers 3 active oldest votes up vote 2 down vote This example uses the validation callback mechanism of the parser module. The signature of callbacks expected by xmlSchemaSetParserErrors seems to be the same. #include #include #include #include #include #include #include #include struct ParserContext { ParserContext() : context(xmlNewParserCtxt()) {} ~ParserContext() { xmlFreeParserCtxt(context); } xmlParserCtxtPtr context;

Sign in Pricing Blog Support Search GitHub This repository Watch 1 Star 2 Fork 1 trevorlinton/libxml2 Code Issues 0 Pull requests 0 Projects 0 Pulse Graphs Permalink Branch: master Switch branches/tags Branches Tags master Nothing to show Nothing to show Find file Copy path libxml2/error.c Fetching contributors… Cannot retrieve contributors at this time Raw Blame History 997 lines (925 sloc) 26.7 KB /* * error.c: module displaying/handling XML parser errors * * See Copyright for the status of this software. * * Daniel Veillard */ #define IN_LIBXML #include "libxml.h" #include #include #include #include #include #include void XMLCDECL xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, const char *msg, ...); #define XML_GET_VAR_STR(msg, str) { \ int size, prev_size = -1; \ int chars; \ char *larger; \ va_list ap; \ \ str = (char *) xmlMalloc(150); \ if (str != NULL) { \ \ size = 150; \ \ while (size < 64000) { \ va_start(ap, msg); \ chars = vsnprintf(str, size, msg, ap); \ va_end(ap); \ if ((chars > -1) && (chars < size)) { \ if (prev_size == chars) { \ break; \ } else { \ prev_size = chars; \ } \ } \ if (chars > -1) \ size += chars + 1; \ else \ size += 100; \ if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\ break; \ } \ str = larger; \ }} \ } /************************************************************************ * * * Handling of out of context errors * * * ************************************************************************/ /** * xmlGenericErrorDefaultFunc: * @ctx: an error context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Default handler for out of context error messages. */ void XMLCDECL xmlGenericErrorDefaultFunc(void *ct

 

Related content

No related pages.