int main(){ exception e; FILE *f = NULL ,*fw = NULL; int i = 0,t,result,count=0; wchar_t *tmpString; UByte *xml = NULL; // this is the buffer containing the XML content, UByte means unsigned byte VTDGen *vg = NULL; // This is the VTDGen that parses XML VTDNav *vn = NULL; // This is the VTDNav that navigates the VTD records AutoPilot *ap = NULL; XMLModifier *xm = NULL; // allocate a piece of buffer then reads in the document content // assume "c:\soap2.xml" is the name of the file f = fopen("oldpo.vxl","rb"); fw = fopen("newpo_update.xml","wb"); Try{ vg = createVTDGen(); vn = loadIndex(vg,f); ap = createAutoPilot2(); xm = createXMLModifier(); if (selectXPath(ap,L"/purchaseOrder/items/item[@partNum='872-AA']")){ bind(ap,vn); bind4XMLModifier(xm,vn); while((result=evalXPath(ap))!= -1){ remove4XMLModifier(xm); insertBeforeElement(xm,L"<something/>"); } } if (selectXPath(ap,L"/purchaseOrder/items/item/USPrice[.<40]/text()")){ while((result=evalXPath(ap))!= -1){ updateToken(xm,result,L"200"); } } output(xm,fw); fclose(f); fclose(fw); // remember C has no automatic garbage collector // needs to deallocate manually. freeVTDNav(vn); freeVTDGen(vg); freeXMLModifier(xm); freeAutoPilot(ap); } Catch (e) { // manual garbage collection here freeVTDGen(vg); } return 0; }
int main(){ exception e; VTDGen *vg = NULL; VTDNav *vn = NULL; AutoPilot *ap = NULL; UCSChar *string = NULL; int i; Try{ ap = createAutoPilot2(); selectXPath(ap,L"/a/b/text()"); vg = createVTDGen(); if (parseFile(vg,FALSE,"d:/ximpleware_2.2_c/vtd-xml/codeGuru/2/input.xml")){ vn = getNav(vg); bind(ap,vn); while((i=evalXPath(ap))!=-1){ string = toString(vn,i); wprintf(L"the text node value is %d ==> %s \n",i,string); free(string); } free(vn->XMLDoc); } else { free(vg->XMLDoc); } }Catch(e){// handle various types of exceptions here } freeAutoPilot(ap); freeVTDGen(vg); freeVTDNav(vn); return 0; }
int main(){ exception e; VTDGen *vg = NULL; VTDNav *vn = NULL; AutoPilot *ap1 = NULL; FILE *f = NULL; UCSChar *string = NULL; int i; Try{ vg = createVTDGen(); if (parseFile(vg,TRUE,"d:/ximpleware_2.2_c/vtd-xml/codeGuru/13/old_cd.xml")==FALSE){ free(vg->XMLDoc); freeVTDGen(vg); return 0; } ap1 = createAutoPilot2(); selectXPath(ap1,L"/CATALOG/CD[PRICE=10.2]/*/text()"); vn = getNav(vg); bind(ap1,vn); while((i=evalXPath(ap1))!=-1){ overWrite(vn,i,"",0,0); } f= fopen("d:/ximpleware_2.2_c/vtd-xml/codeGuru/13/new_cd.xml","wb"); fwrite(vn->XMLDoc+vn->docOffset,1,vn->docLen,f); fclose(f); free(vn->XMLDoc); }Catch(e){// handle various types of exceptions here } freeAutoPilot(ap1); freeVTDGen(vg); freeVTDNav(vn); return 0; }
int main(){ exception e; VTDGen *vg = NULL; VTDNav *vn = NULL; AutoPilot *ap = NULL; XMLModifier *xm = NULL; FILE *f = NULL; UCSChar *string = NULL; int i; f = fopen("d:/ximpleware_2.2_c/vtd-xml/codeGuru/6/input.vxl","rb"); if (f==NULL) return 0; Try{ xm = createXMLModifier(); ap = createAutoPilot2(); selectXPath(ap,L"/a/b"); vg = createVTDGen(); vn = loadIndex (vg,f); bind(ap,vn); bind4XMLModifier(xm,vn); while((i=evalXPath(ap))!=-1){ insertAttribute(xm,L" attr1='val'"); } output2(xm,"d:/ximpleware_2.2_c/vtd-xml/codeGuru/6/new.xml"); free(vn->XMLDoc); }Catch(e){// handle various types of exceptions here } fclose(f); freeAutoPilot(ap); freeXMLModifier(xm); freeVTDGen(vg); freeVTDNav(vn); return 0; }
void main() { exception e; Try{ VTDGen *vg = NULL; /* This is the VTDGen that parses XML */ VTDNav *vn = NULL; /* This is the VTDNav that navigates the VTD records */ AutoPilot *ap = NULL, *ap2=NULL; XMLModifier *xm = NULL; ElementFragmentNs *ef = NULL; int i= -1; Long l= -1; vg = createVTDGen(); ap = createAutoPilot2(); ap2 = createAutoPilot2(); xm = createXMLModifier(); selectXPath(ap,L"(/*/*/*)[position()>1 and position()<4]"); selectXPath(ap2,L"/*/*/*"); if (parseFile(vg,TRUE,"soap2.xml")) { //FILE *f1 = fopen("d:/new3.xml","wb"); vn = getNav(vg); bind(ap,vn); bind(ap2,vn); bind4XMLModifier(xm,vn); evalXPath(ap2); ef = getElementFragmentNs(vn); while( (i=evalXPath(ap))!=-1) { insertAfterElement4(xm,ef); printf(" index %d \n",i); } //fwrite(vn->XMLDoc+vn->docOffset,sizeof(UByte),vn->docLen,f1); output2(xm,"new3.xml"); //fclose(f1); free(vn->XMLDoc); freeVTDNav(vn); } freeElementFragmentNs(ef); freeXMLModifier(xm); freeAutoPilot(ap); freeAutoPilot(ap2); freeVTDGen(vg); } Catch(e) { printf("exception !!!!!!!!!!! \n"); } }
static int evx_xpath_query (Exception_handlers_t *p_handlers, EIF_POINTER a_node_context, EIF_POINTER a_xpath_query, Boolean is_start) // returns a nodeset index // -1 if finished { VTDNav *node_context = (VTDNav *)a_node_context; AutoPilot *xpath_query = (AutoPilot *)a_xpath_query; exception e; int result = 0; Try { if (is_start) AP_bind (xpath_query, node_context); result = evalXPath(xpath_query); } Catch (e) { // manual garbage collection here raise_eiffel_exception (p_handlers, &e); } return result; }
int main(){ exception e; VTDGen *vg = NULL; VTDNav *vn = NULL; AutoPilot *ap1 = NULL; XMLModifier *xm = NULL; UCSChar *string = NULL; int i; Long l; ba0=L" "; ba1=L" "; ba2=L" "; ba3=L" "; ba4=L" "; ba5=L" "; Try{ vg = createVTDGen(); if (parseFile(vg,TRUE,"d:/ximpleware_2.2_c/vtd-xml/codeGuru/11/old_cd.xml")==FALSE){ free(vg->XMLDoc); freeVTDGen(vg); return 0; } xm = createXMLModifier(); ap1 = createAutoPilot2(); selectXPath(ap1,L"/CATALOG/CD"); vn = getNav(vg); bind(ap1,vn); bind4XMLModifier(xm,vn); while((i=evalXPath(ap1))!=-1){ convert(vn,xm); } output2(xm,"d:/ximpleware_2.2_c/vtd-xml/codeGuru/11/cd_template.xml"); free(vn->XMLDoc); }Catch(e){// handle various types of exceptions here } freeAutoPilot(ap1); freeXMLModifier(xm); freeVTDGen(vg); freeVTDNav(vn); return 0; }
int main(){ exception e; FILE *f = NULL; int i = 0,count=0,par_count=0,v=0; char* filename = "./bioinfo.xml"; struct stat s; UByte *xml = NULL; // this is the buffer containing the XML content, UByte means unsigned byte VTDGen *vg = NULL; // This is the VTDGen that parses XML VTDNav *vn = NULL; // This is the VTDNav that navigates the VTD records AutoPilot *ap = NULL; // allocate a piece of buffer then reads in the document content // assume "c:\soap2.xml" is the name of the file f = fopen(filename,"r"); stat(filename,&s); i = (int) s.st_size; wprintf(L"size of the file is %d \n",i); xml = (UByte *)malloc(sizeof(UByte) *i); i = fread(xml,sizeof(UByte),i,f); Try{ vg = createVTDGen(); setDoc(vg,xml,i); parse(vg,TRUE); vn = getNav(vg); ap = createAutoPilot2(); bind(ap,vn); if (selectXPath(ap,L"/bix/package/command/parlist")){ while(evalXPath(ap)!= -1){ count++; } } if (selectXPath(ap,L"/bix/package/command/parlist/par")){ while(evalXPath(ap)!= -1){ par_count++; } } wprintf(L"count ==> %d \n",count); wprintf(L"par_count ==> %d \n",par_count); toElement(vn,ROOT); selectElement(ap,L"par"); while(iterateAP(ap)){ if (getCurrentDepth(vn) == 4){ v++; } } wprintf(L"verify ==> %d \n",v); fclose(f); // remember C has no automatic garbage collector // needs to deallocate manually. freeVTDNav(vn); freeVTDGen(vg); freeAutoPilot(ap); } Catch (e) { if (e.et == parse_exception) printf("parse exception e ==> %s \n %s\n", e.msg, e.sub_msg); // manual garbage collection here freeVTDGen(vg); } return 0; }
int main(){ exception e; FILE *f = NULL; int i = 0,t,result,count=0; wchar_t *tmpString; char* filename = "./servers.xml"; struct stat s; UByte *xml = NULL; // this is the buffer containing the XML content, UByte means unsigned byte VTDGen *vg = NULL; // This is the VTDGen that parses XML VTDNav *vn = NULL; // This is the VTDNav that navigates the VTD records AutoPilot *ap = NULL; // allocate a piece of buffer then reads in the document content // assume "c:\soap2.xml" is the name of the file f = fopen(filename,"r"); stat(filename,&s); i = (int) s.st_size; wprintf(L"size of the file is %d \n",i); xml = (UByte *)malloc(sizeof(UByte) *i); i = fread(xml,sizeof(UByte),i,f); Try{ vg = createVTDGen(); setDoc(vg,xml,i); parse(vg,TRUE); vn = getNav(vg); ap = createAutoPilot2(); declareXPathNameSpace(ap,L"ns1",L"http://purl.org/dc/elements/1.1/"); if (selectXPath(ap,L"//ns1:*")){ bind(ap,vn); while((result=evalXPath(ap))!= -1){ wprintf(L"result is %d \n",result); tmpString = toString(vn,result); wprintf(L"Element name ==> %ls \n",tmpString); free(tmpString); t = getText(vn); if (t!=-1){ tmpString = toNormalizedString(vn,t); wprintf(L" text ==> %ls \n",tmpString); free(tmpString); } wprintf(L"\n =======================\n "); count ++; } } wprintf(L"\nTotal number of elements %d \n",count); fclose(f); // remember C has no automatic garbage collector // needs to deallocate manually. freeVTDNav(vn); freeVTDGen(vg); freeAutoPilot(ap); } Catch (e) { if (e.et == parse_exception) wprintf(L"parse exception e ==> %s \n %s\n", e.msg, e.sub_msg); // manual garbage collection here freeVTDGen(vg); } return 0; }