char *test_read_input() { FILE *f; /* open, read and parse some invalid xml */ f = fopen("test.invalid.xml", "r"); mu_assert("read invalid xml", read_input(f) == 0); fclose(f); mu_assert("parse invalid xml", xml_parse(buf) == XML_STATUS_INVALID); /* open, read and parse some valid xml */ f = fopen("test.xml", "r"); mu_assert("read valid xml", read_input(f) == 0); fclose(f); mu_assert("buffer contains request", strncmp(buf,"<request>", 9) == 0); mu_assert("parse some valid xml", xml_parse(buf) == XML_STATUS_OK); /* fetch value of an element */ char *value = xml_element("//username"); mu_assert("perform xpath search for element", value != NULL); mu_assert("get value of xml element", strcmp(value, "iamauser") == 0); xml_free(value); xml_cleanup(); return 0; }
void read_xml_file( char *fname ) { char tag[MaxStr], contents[MaxStr], tagname[MaxStr], attrname[MaxStr], value[MaxStr]; float x1, y1, z1, x2, y2, z2, t0, t1; int linum=0; FILE *infile=0, *outfile=0; infile = fopen(fname,"r"); if (infile==0) {printf("Error: Cannot open input file '%s'.\n",fname); exit(1);} xml_parse( infile, tag, contents, MaxStr, &linum ); while (tag[0]!='\0') { xml_grab_tag_name( tag, tagname, MaxStr ); /* Get tag name. */ /* Add your application code here to accept tag-name, such as: */ printf("Tag name = '%s'\n", tagname ); xml_grab_attrib( tag, attrname, value, MaxStr ); /* Get any attributes within tag. */ while (value[0] != '\0') { /* Add application code here to accept attribute attrname and value, such as: */ printf(" Attribute: %s = '%s'\n", attrname, value ); xml_grab_attrib( tag, attrname, value, MaxStr ); /* Get next attribute, if any. */ } /* Add application code here to accept contents between tags, such as: */ printf(" Contents = '%s'\n", contents ); xml_parse( infile, tag, contents, MaxStr, &linum ); /* Get next tag, if any. */ } fclose(infile); }
/** \brief Parse a soap reply */ upnp_err_t upnp_call_t::parse_soap_rep(const datum_t &xml_datum, strvar_db_t &strvar_db) const throw() { // log to debug KLOG_DBG("enter xml_datum=" << xml_datum.to_stdstring()); // set the document to parse xml_parse_doc_t xml_parse_doc; xml_parse_doc.set_document(xml_datum); // if it is impossible to parse the xml, return an error if( xml_parse_doc.is_null() ){ KLOG_ERR("unable to parse the xml in " << xml_datum); return upnp_err_t(upnp_err_t::ERROR, "unable to parse the xml"); } // init the xml_parse_t on this document xml_parse_t xml_parse(&xml_parse_doc); // go inside the "Body" try { xml_parse.goto_children().goto_firstsib("Body").goto_children(); }catch(xml_except_t &e){ KLOG_ERR("unable to parse the xml 'subbody' due to " << e.what() << " in " << xml_datum); return upnp_err_t(upnp_err_t::ERROR, "unable to parse the xml 'subbody' due to " + e.what()); } // if this is a SOAP_FAULT, goto the fault parser if( xml_parse.has_firstsib("Fault") ) return parse_soap_rep_fault(xml_datum, xml_parse, strvar_db); // else goto the success parser return parse_soap_rep_success(xml_datum, xml_parse, strvar_db); }
void xmlrpc_parse_response2(xmlrpc_env * const envP, const char * const xmlData, size_t const xmlDataLen, xmlrpc_value ** const resultPP, int * const faultCodeP, const char ** const faultStringP) { /*---------------------------------------------------------------------------- Given some XML text, attempt to parse it as an XML-RPC response. If the response is a regular, valid response, return a new reference to the appropriate value as *resultP and return NULL as *faultStringP and nothing as *faultCodeP. If the response is valid, but indicates a failure of the RPC, return the fault string in newly malloc'ed space as *faultStringP and the fault code as *faultCodeP and nothing as *resultP. If the XML text is not a valid response or something prevents us from parsing it, return a description of the error as *envP and nothing else. -----------------------------------------------------------------------------*/ xml_element * response; XMLRPC_ASSERT_ENV_OK(envP); XMLRPC_ASSERT(xmlData != NULL); /* SECURITY: Last-ditch attempt to make sure our content length is legal. ** XXX - This check occurs too late to prevent an attacker from creating ** an enormous memory block, so you should try to enforce it ** *before* reading any data off the network. */ if (xmlDataLen > xmlrpc_limit_get(XMLRPC_XML_SIZE_LIMIT_ID)) xmlrpc_env_set_fault_formatted( envP, XMLRPC_LIMIT_EXCEEDED_ERROR, "XML-RPC response too large. Our limit is %u characters. " "We got %u characters", xmlrpc_limit_get(XMLRPC_XML_SIZE_LIMIT_ID), xmlDataLen); else { xmlrpc_env env; xmlrpc_env_init(&env); xml_parse(&env, xmlData, xmlDataLen, &response); if (env.fault_occurred) setParseFault(envP, "Not valid XML. %s", env.fault_string); else { /* Pick apart and verify our structure. */ if (xmlrpc_streq(xml_element_name(response), "methodResponse")) { parseMethodResponseElt(envP, response, resultPP, faultCodeP, faultStringP); } else setParseFault(envP, "XML-RPC response must consist of a " "<methodResponse> element. " "This has a <%s> instead.", xml_element_name(response)); xml_element_free(response); } xmlrpc_env_clean(&env); } }
void xml_parse_generic_container( ContainerT <T, L...>& value, NodeName const& name, PropertyTree const& object, XmlParseOptions options = {}, typename std::enable_if < has_random_access_iterator <ContainerT, L...>::value || has_bidirectional_iterator <ContainerT, L...>::value || has_forward_iterator <ContainerT, L...>::value >::type* = nullptr) { try { if (!options.stateMixing) value.clear(); auto parent = name.parent(); SXML_GET_CHILD(parent, pt, {}); auto range = pt.equal_range(name.getName()); for (auto i = range.first; i != range.second; ++i) { T temp; xml_parse(temp, "", i->second, options); emplacer<ContainerT<T, L...>>::emplace(value, std::move(temp)); } } SXML_DEFAULT_CATCH({}, {}) } } }
static void parseCallXml(xmlrpc_env * const envP, const char * const xmlData, size_t const xmlDataLen, xml_element ** const callElemPP) { /*---------------------------------------------------------------------------- Parse the XML of an XML-RPC call. -----------------------------------------------------------------------------*/ xml_element * callElemP; xmlrpc_env env; xmlrpc_env_init(&env); xml_parse(&env, xmlData, xmlDataLen, &callElemP); if (env.fault_occurred) xmlrpc_env_set_fault_formatted( envP, env.fault_code, "Call is not valid XML. %s", env.fault_string); else { if (!xmlrpc_streq(xml_element_name(callElemP), "methodCall")) setParseFault(envP, "XML-RPC call should be a <methodCall> element. " "Instead, we have a <%s> element.", xml_element_name(callElemP)); if (envP->fault_occurred) xml_element_free(callElemP); } *callElemPP = callElemP; xmlrpc_env_clean(&env); }
int main( int argc, char **argv ) { FILE *fp = 0; if( argc < 2 ) { fprintf( stderr, "Usage : %s filename.\n", argv[0] ); exit( -1 ); } fp = fopen( argv[1], "r" ); if( fp == 0 ) { fprintf( stderr, "Unable to open %s.\n", argv[1] ); exit( -1 ); } { struct xmlDocument *doc = xmldoc_new( fp ); xml_seterrorfn( error_log ); xml_parse( doc ); dump_node( doc->root ); xmldoc_free( doc ); } fclose( fp ); return 0; }
/* we add another function: * XmlNode *xml_load_buffer(const char *buffer) to fit our need. */ XmlNode* xml_load_buffer(const char * buffer, unsigned int buffer_len) { struct XMLBUF xml; XmlNode *ret = NULL; xml.error = 0; xml.eof = 1; xml.read_index = 0; xml.fptr = NULL; xml.buf = (char *)malloc(sizeof(char) * buffer_len + 1); if(!xml.buf) goto xml_load_fail_malloc_buf; memset(xml.buf, 0, buffer_len + 1); xml.len = buffer_len; memcpy(xml.buf, buffer, buffer_len); ret = xml_parse(&xml); if(xml.error) { xml_free(ret); ret = NULL; } free(xml.buf); xml_load_fail_malloc_buf: return ret; }
/* bootstrap the structures for xml_parse() to be able to get started */ XmlNode* xml_load(const char * filename) { struct XMLBUF xml; XmlNode *ret = NULL; // printf("xml_load(\"%s\");\n", filename); xml.error = 0; xml.eof = 0; xml.read_index = 0; xml.fptr = fopen(filename, "rb"); if(!xml.fptr) return NULL; xml.buf = malloc(BUFFER+1); if(!xml.buf) goto xml_load_fail_malloc_buf; xml.buf[BUFFER]=0; xml.len = BUFFER; xml_read_file(&xml); ret = xml_parse(&xml); if(xml.error) { xml_free(ret); ret = NULL; } free(xml.buf); xml_load_fail_malloc_buf: fclose(xml.fptr); return ret; }
int xml_validate(request *req, char *xstr, int len) { int rval; tag_t *parent = NULL; rval = xml_parse(req, parent, xstr, len); return rval; }
typename std::enable_if <!isAttribute<U>::value && !isContent<U>::value && !isInline<U>::value>::type memberTypeDependendParser(U& value, bool attributeRun, NodeName const& name, PropertyTree const& object, XmlParseOptions const& options) { if (attributeRun) return; xml_parse(value, name, object, options); }
int main (int argc, char **argv) { XML *xml; QUEUE *q; QUEUEROW *r; MIME *m; char *ch; int arg = 1; xml = xml_parse (PhineasConfig); loadpath (cfg_installdir (xml)); queue_init (xml); /* test folder polling */ if ((argc > arg) && (strcmp (argv[arg], "-f") == 0)) { fpoller_register ("ebxml", ebxml_fprocessor); fpoller_task (xml); arg++; ran = 0; } /* test message from queue */ if ((argc > arg) && (strcmp (argv[arg], "-m") == 0)) { if ((q = queue_find ("MemSendQ")) == NULL) error ("can't find MemSendQ"); else if ((r = queue_pop (q)) == NULL) error ("can't pop row\n"); /* else if ((m = ebxml_getsoap (xml, r)) == NULL) error ("can't get soap container\n"); */ else if ((m = ebxml_getmessage (xml, r)) == NULL) error ("can't get message\n"); else if ((ch = mime_format (m)) == NULL) error ("Can't format soap containter\n"); else debug ("message MIME\n%s\n", ch); free (ch); mime_free (m); queue_row_free (r); arg++; } /* test queue polling */ if ((argc > arg) && (strcmp (argv[arg], "-q") == 0)) { qpoller_register ("EbXmlSndQ", ebxml_qprocessor); qpoller_task (xml); arg++; ran = 0; } queue_shutdown (); xml_free (xml); info ("%s %s\n", argv[0], Errors ? "failed" : "passed"); exit (Errors); }
static gchar * update_apply_xslt (updateJobPtr job) { xsltStylesheetPtr xslt = NULL; xmlOutputBufferPtr buf; xmlDocPtr srcDoc = NULL, resDoc = NULL; gchar *output = NULL; g_assert (NULL != job->result); do { srcDoc = xml_parse (job->result->data, job->result->size, NULL); if (!srcDoc) { g_warning("fatal: parsing request result XML source failed (%s)!", job->request->filtercmd); break; } /* load localization stylesheet */ xslt = xsltParseStylesheetFile (job->request->filtercmd); if (!xslt) { g_warning ("fatal: could not load filter stylesheet \"%s\"!", job->request->filtercmd); break; } resDoc = xsltApplyStylesheet (xslt, srcDoc, NULL); if (!resDoc) { g_warning ("fatal: applying stylesheet \"%s\" failed!", job->request->filtercmd); break; } buf = xmlAllocOutputBuffer (NULL); if (-1 == xsltSaveResultTo (buf, resDoc, xslt)) { g_warning ("fatal: retrieving result of filter stylesheet failed (%s)!", job->request->filtercmd); break; } #ifdef LIBXML2_NEW_BUFFER if (xmlOutputBufferGetSize (buf) > 0) output = xmlCharStrdup (xmlOutputBufferGetContent (buf)); #else if (xmlBufferLength (buf->buffer) > 0) output = xmlCharStrdup (xmlBufferContent (buf->buffer)); #endif xmlOutputBufferClose (buf); } while (FALSE); if (srcDoc) xmlFreeDoc (srcDoc); if (resDoc) xmlFreeDoc (resDoc); if (xslt) xsltFreeStylesheet (xslt); return output; }
static void test_expat (void) { xmlrpc_env env; xml_element *elem, *array, *data, *value1, *i4; char *cdata; size_t size; xmlrpc_env_init(&env); /* Parse a moderately complex XML document. */ xml_parse(&env, expat_data, strlen(expat_data), &elem); TEST_NO_FAULT(&env); TEST(elem != NULL); /* Verify our results. */ TEST(streq(xml_element_name(elem), "value")); TEST(xml_element_children_size(elem) == 1); array = xml_element_children(elem)[0]; TEST(streq(xml_element_name(array), "array")); TEST(xml_element_children_size(array) == 1); data = xml_element_children(array)[0]; TEST(streq(xml_element_name(data), "data")); TEST(xml_element_children_size(data) > 1); value1 = xml_element_children(data)[0]; TEST(streq(xml_element_name(value1), "value")); TEST(xml_element_children_size(value1) == 1); i4 = xml_element_children(value1)[0]; TEST(streq(xml_element_name(i4), "i4")); TEST(xml_element_children_size(i4) == 0); cdata = xml_element_cdata(i4); size = xml_element_cdata_size(i4); TEST(size == strlen("2147483647")); TEST(memcmp(cdata, "2147483647", strlen("2147483647")) == 0); /* Test cleanup code (w/memprof). */ xml_element_free(elem); /* Test broken XML */ xml_parse(&env, expat_error_data, strlen(expat_error_data), &elem); TEST(env.fault_occurred); xmlrpc_env_clean(&env); }
/****************************************************************************** * *Function: conf_init * *Description: open and parse xml config file * *Input: none * *Output: none * *Return: CONF_SUCCESS/CONF_FAIL * *Date: 2016/8/22 * ****************************************************************************/ int conf_init() { if(xml_open(CONF_FNAME) == PARSE_FAIL) return CONF_FAIL; if(xml_parse() == PARSE_FAIL) return CONF_FAIL; return CONF_SUCCESS; }
VMINT vm_xml_parse( VM_XML_PARSER_STRUCT *parser, const VMCHAR *xmlsource, VMINT length) { int ret = VM_XML_RESULT_FAIL; ret = xml_new_parser(&mtk_xml_parser); if (XML_RESULT_OK != ret) { MMI_TRACE(MMI_MRE_TRC_ERROR, TRC_MRE_VMXML_336 , ret); xml_close_parser(&mtk_xml_parser); return -1; } xml_configure_memory(&mtk_xml_parser, vm_malloc, vm_free); xml_register_doctype_handler( &mtk_xml_parser, parser->start_doctype_hdlr, parser->end_doctype_hdlr); xml_register_element_handler( &mtk_xml_parser, parser->start_elem_hdlr, parser->end_elem_hdlr); xml_register_data_handler( &mtk_xml_parser, parser->data_hdlr); if(0 == length) { ret = xml_parse(&mtk_xml_parser, (VMUWSTR)vm_ucs2_string_by_ascii((VMSTR)xmlsource)); } else { ret = xml_parse_buffer(&mtk_xml_parser, xmlsource, length); } xml_close_parser(&mtk_xml_parser); if (XML_RESULT_OK!= ret) { return -1; } return VM_XML_RESULT_OK; }
int main (int argc, char **argv) { XML *xml; char *ch; xml = xml_parse (PhineasConfig); queue_register ("FileQueue", fileq_connect); queue_init (xml); debug ("begin registration...\n"); qpoller_register ("EbXmlSndQ", test_qprocessor); qpoller_task (xml); xml_free (xml); info ("%s unit test completed\n", argv[0]); }
static int medin_processf( fields *medin, char *data, char *filename, long nref, param *p ) { int status; xml top; xml_init( &top ); xml_parse( data, &top ); status = medin_assembleref( &top, medin ); xml_free( &top ); if ( status==BIBL_OK ) return 1; return 0; }
static void test_parse_xml_call(void) { xmlrpc_env env; const char *method_name; xmlrpc_value *params; int i1, i2; const char **bad_call; xml_element *elem; xmlrpc_env_init(&env); /* Parse a valid call. */ xmlrpc_parse_call(&env, serialized_call, strlen(serialized_call), &method_name, ¶ms); TEST_NO_FAULT(&env); TEST(params != NULL); xmlrpc_decompose_value(&env, params, "(ii)", &i1, &i2); xmlrpc_DECREF(params); TEST_NO_FAULT(&env); TEST(streq(method_name, "gloom&doom")); TEST(i1 == 10 && i2 == 20); strfree(method_name); /* Test some poorly-formed XML data. */ xmlrpc_parse_call(&env, unparseable_value, strlen(unparseable_value), &method_name, ¶ms); TEST_FAULT(&env, XMLRPC_PARSE_ERROR); TEST(method_name == NULL && params == NULL); /* Next, check for bogus values. These are all well-formed XML, but they aren't legal XML-RPC. */ for (bad_call = bad_calls; *bad_call != NULL; ++bad_call) { /* First, check to make sure that our test case is well-formed XML. ** (It's easy to make mistakes when writing the test cases!) */ xml_parse(&env, *bad_call, strlen(*bad_call), &elem); TEST_NO_FAULT(&env); xml_element_free(elem); /* Now, make sure the higher-level routine barfs appropriately. */ xmlrpc_parse_call(&env, *bad_call, strlen(*bad_call), &method_name, ¶ms); TEST_FAULT(&env, XMLRPC_PARSE_ERROR); TEST(method_name == NULL && params == NULL); } xmlrpc_env_clean(&env); }
void xmlrpc_parse_value_xml(xmlrpc_env * const envP, const char * const xmlData, size_t const xmlDataLen, xmlrpc_value ** const valuePP) { /*---------------------------------------------------------------------------- Compute the xmlrpc_value represented by the XML document 'xmlData' (of length 'xmlDataLen' characters), which must consist of a single <value> element. Return that xmlrpc_value. We call convert_array() and convert_struct(), which may ultimately call us recursively. Don't recurse any more than 'maxRecursion' times. This isn't generally useful in XML-RPC programs, because such programs parse a whole XML-RPC call or response document, and never see the XML text of just a <value> element. But a program may do some weird form of XML-RPC processing or just borrow Xmlrpc-c's value serialization facilities for something unrelated to XML-RPC. In any case, it makes sense to have an inverse of xmlrpc_serialize_value2(), which generates XML text from an xmlrpc_value. -----------------------------------------------------------------------------*/ xmlrpc_env env; xml_element * valueEltP; XMLRPC_ASSERT_ENV_OK(envP); XMLRPC_ASSERT(xmlData != NULL); xmlrpc_env_init(&env); xml_parse(&env, xmlData, xmlDataLen, &valueEltP); if (env.fault_occurred) { setParseFault(envP, "Not valid XML. %s", env.fault_string); } else { if (xmlrpc_streq(xml_element_name(valueEltP), "value")) { unsigned int const maxRecursion = (unsigned int) xmlrpc_limit_get(XMLRPC_NESTING_LIMIT_ID); xmlrpc_parseValue(envP, maxRecursion, valueEltP, valuePP); } else setParseFault(envP, "XML-RPC value XML document must consist of " "a <value> element. This has a <%s> instead.", xml_element_name(valueEltP)); xml_element_free(valueEltP); } xmlrpc_env_clean(&env); }
int main(int argc,char *argv[]) { FILE *f=fopen(argv[1],"r"); // Parse XML file struct foo *b=(struct foo *)xml_parse(f,"root",&myschema,metafind(&myschema, "foo"),1); struct item *i; // Access values in foo printf("root->val = %d\n",b->val); printf("root->val_name = %s\n",b->val_name); printf("root->items->val = %d\n",b->items->val); printf("root->items->next->val = %d\n",b->items->next->val); printf("root->items->next->next->val = %d\n",b->items->next->next->val); // Print in various formats xml_print(stdout,"root",0,(struct base *)b); lisp_print(stdout,"root",0,(struct base *)b); lisp_print_untagged(stdout,"root",0,(struct base *)b); indent_print(stdout,"root",0,(struct base *)b); indent_print_untagged(stdout,"root",0,(struct base *)b); json_print(stdout,NULL,0,(struct base *)b,0); // Create a database within C b=mk(&myschema, "foo"); b->val=10; b->val_name=strdup("Hello"); // Build list i=b->items=mk(&myschema, "item"); i->val=7; i=i->next=mk(&myschema, "item"); i->val=8; i=i->next=mk(&myschema, "item"); i->val=9; // Print it xml_print(stdout,"root",0,(struct base *)b); return 0; }
/* * load a configuration, decrypting it if credentials found */ XML *cfg_load (char *path) { XML *xml; cfg_clean (path); if ((xml = xml_load (path)) == NULL) return (NULL); if (strcmp (xml_root (xml), "Phineas")) { unsigned char *p; xcrypt_decrypt (xml, &p, ConfigCert, NULL, ConfigPass); xml_free (xml); xml = xml_parse (p); free (p); } return (xml); }
static void google_subscription_opml_cb (subscriptionPtr subscription, const struct updateResult * const result, updateFlags flags) { AolSourcePtr gsource = (AolSourcePtr) subscription->node->data; subscription->updateJob = NULL; if (result->data) { xmlDocPtr doc = xml_parse (result->data, result->size, NULL); if(doc) { xmlNodePtr root = xmlDocGetRootElement (doc); /* Go through all existing nodes and remove those whose URLs are not in new feed list. Also removes those URLs from the list that have corresponding existing nodes. */ node_foreach_child_data (subscription->node, aol_source_check_for_removal, (gpointer)root); node_foreach_child (subscription->node, aol_source_migrate_node); opml_source_export (subscription->node); /* save new feed list tree to disk to ensure correct document in next step */ xpath_foreach_match (root, "/object/list[@name='subscriptions']/object", aol_source_merge_feed, (gpointer)gsource); opml_source_export (subscription->node); /* save new feeds to feed list */ subscription->node->available = TRUE; xmlFreeDoc (doc); } else { /** @todo The session seems to have expired */ g_warning ("Unable to parse OPML list from google, the session might have expired.\n"); } } else { subscription->node->available = FALSE; debug0 (DEBUG_UPDATE, "google_subscription_opml_cb(): ERROR: failed to get subscription list!\n"); } if (!(flags & NODE_SOURCE_UPDATE_ONLY_LIST)) node_foreach_child_data (subscription->node, node_update_subscription, GUINT_TO_POINTER (0)); }
static void testParseBadResult(void) { /*---------------------------------------------------------------------------- Test parsing of data that is supposed to be a response, but is not valid. It looks like a valid success response, but the result value is not valid XML-RPC. -----------------------------------------------------------------------------*/ unsigned int i; for (i = 0; bad_values[i] != NULL; ++i) { const char * const bad_resp = bad_values[i]; xmlrpc_env env; xmlrpc_value * valueP; xml_element *elem; int faultCode; const char * faultString; xmlrpc_env_init(&env); /* First, check to make sure that our test case is well-formed XML. ** (It's easy to make mistakes when writing the test cases!) */ xml_parse(&env, bad_resp, strlen(bad_resp), &elem); TEST_NO_FAULT(&env); xml_element_free(elem); /* Now, make sure the higher-level routine barfs appropriately. */ xmlrpc_parse_response2(&env, bad_resp, strlen(bad_resp), &valueP, &faultCode, &faultString); TEST_FAULT(&env, XMLRPC_PARSE_ERROR); xmlrpc_env_clean(&env); xmlrpc_env_init(&env); /* And again with the old interface */ valueP = xmlrpc_parse_response(&env, bad_resp, strlen(bad_resp)); TEST_FAULT(&env, XMLRPC_PARSE_ERROR); TEST(valueP == NULL); xmlrpc_env_clean(&env); } }
static void theme_add_theme(char *xmlfile, option_t *option) { state s; s.option = option; s.theme = NULL; if (xml_parse(xmlfile, "theme", theme_data_cb, theme_open_cb, theme_close_cb, &s)) DBG_ERROR("Error loading theme file '%s'", xmlfile); if (s.theme) { free(s.theme->name); free(s.theme->style); free(s.theme->pieces); free(s.theme->board); free(s.theme->white_name); free(s.theme->black_name); free(s.theme); } }
void test_parse() { char *xml = "<Body UnitCode=\"场所编码\" Code=\"结果代码\" Description=\"结果附加说明\">" "<Table Name=\"记录集名称\" Method=\"处理动作\" Range=\"数据范围\" CmdNo=\"命令号\" Description=\"附加说明\">" "<Item item1=\"值1\" item2=\"值2\" />" "</Table></Body>"; xml_body_ptr body = NULL; printf("\n*** test_parse ***\n"); printf("XML: %s\n", xml); /* parse to body */ body = xml_parse(xml); test_print(body); /* clean body */ xml_body_clean(body); }
int xml_validate(request *req, char *xstr, int len) { int rval; tag_t *parent = NULL; //int i; //char *ch; if(xstr == NULL) return -1; //ch = xstr; //fprintf(stderr,"\r\nInside xml_validate with len:%d & input string: \n",len); //for (i=0; i<len ;i++) //{ // fprintf(stderr,"%c",*ch++); //} rval = xml_parse(req, parent, xstr, len); return rval; }
/****************************************************************************** **函数名称: xml_screat **功 能: 将XML字串转为XML树 **输入参数: ** str: XML字串 ** len: 字串长度限制(-1:表示遇到\0结束) ** opt: 选项信息 **输出参数: **返 回: XML树 **实现描述: ** 1. 初始化栈 ** 2. 初始化xml树 ** 3. 在内存中将文件解析为XML树 **注意事项: **作 者: # Qifeng.zou # 2013.02.05 # ******************************************************************************/ xml_tree_t *xml_screat(const char *str, size_t len, xml_opt_t *opt) { Stack_t stack; xml_tree_t *xml; if ((NULL == str) || ('\0' == str[0])) { return xml_creat_empty(opt); } do { /* 1. 初始化栈 */ if (stack_init(&stack, XML_MAX_DEPTH)) { log_error(opt->log, "Init xml stack failed!"); break; } /* 2. 初始化XML树 */ xml = xml_init(opt); if (NULL == xml) { log_error(opt->log, "Init xml tree failed!"); break; } /* 3. 解析XML文件缓存 */ if (xml_parse(xml, &stack, str, len)) { log_error(xml->log, "Parse xml failed!"); xml_destroy(xml); break; } stack_destroy(&stack); return xml; } while(0); /* 4. 释放内存空间 */ stack_destroy(&stack); return NULL; }
/***************************************************************************** * FUNCTION * mmi_dcd_get_attr_from_sl * DESCRIPTION * this function is used to get tagname by token * PARAMETERS * filename [IN] File name of wap push sl * url [IN] [out] buf to save url * action [IN] [out] buf to save action * RETURNS * if < 0: failed *****************************************************************************/ int mmi_dcd_get_attr_from_sl(const kal_wchar * filename, kal_char ** url, kal_char ** action) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ XML_PARSER_STRUCT parser; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ g_sl_url_p = NULL; g_sl_action_p = NULL; xml_new_parser (&parser); /* xml_configure_memory (&parser, get_ctrl_buffer, free_ctrl_buffer); */ xml_register_element_handler(&parser, dcd_xml_start_elem_hdlr, dcd_xml_end_elem_hdlr); xml_register_data_handler(&parser, dcd_xml_data_hdlr); xml_parse(&parser, (kal_wchar*)filename); xml_close_parser(&parser); if (url) { *url = g_sl_url_p; } if (action) { *action = g_sl_action_p; } /* no need to free, caller will free it */ return 1; }
static void inoreader_source_opml_quick_update_cb (const struct updateResult* const result, gpointer userdata, updateFlags flags) { InoreaderSourcePtr gsource = (InoreaderSourcePtr) userdata; xmlDocPtr doc; if (!result->data) { /* what do I do? */ debug0 (DEBUG_UPDATE, "InoreaderSource: Unable to get unread counts, this update is aborted."); return; } doc = xml_parse (result->data, result->size, NULL); if (!doc) { debug0 (DEBUG_UPDATE, "InoreaderSource: The XML failed to parse, maybe the session has expired. (FIXME)"); return; } xpath_foreach_match (xmlDocGetRootElement (doc), "/object/list[@name='unreadcounts']/object", inoreader_source_opml_quick_update_helper, gsource); xmlFreeDoc (doc); }