EIF_POINTER evx_create_xpath_query_for_namespace ( Exception_handlers_t *p_handlers, EIF_POINTER a_xpath, EIF_POINTER a_ns_prefix, EIF_POINTER a_ns_url ) { UCSChar *xpath = (UCSChar *)a_xpath, *ns_prefix = (UCSChar *)a_ns_prefix, *ns_url = a_ns_url; exception e; AutoPilot *result = NULL; Try { result = createAutoPilot2(); declareXPathNameSpace (result, ns_prefix, ns_url); selectXPath(result, xpath); } Catch (e) { // manual garbage collection here freeAutoPilot(result); raise_eiffel_exception (p_handlers, &e); } return (EIF_POINTER)result; }
void main(){ wchar_t* tests[] = { L"/descendant::test:*", L"/descendant::test:*", L"/descendant::test:e", L"/descendant::test:f", L"/root/test:*/text()", L"a/d[2]/e", L"*[c or d]", L"a/c[d]", L"a/c[d=\"Text for D\"]", L"a[3][@a1=\"va1\"]", L"a[@a1=\"va1\"][1]", L"a[@a1=\"va1\"]", L"/root/a/c/../@a1", L"/root/a/..", L".//c", L".", L"//c/d", L"//c", L"/root/a//d", L"/root/a/d", L"//a", L"//d", L"a/d[2]/e", L"*/d", L"a[last()]", L"a[1]", L"/root/a[1]/@*", L"/root/a[1]/@a1", L"text()", L"*", L"a", L"/root", L"child::*[self::a or self::b][position()=last() - 1]", L"child::*[self::a or self::b]", L"child::a/child::c[child::d='Text for D']", L"child::a/child::c[child::d]", L"child::a[position()=1][attribute::a1=\"va1\"]", L"child::a[attribute::a1=\"va1\"][position()=1]", L"child::a[attribute::a2=\"va2\"]", L"child::a/child::d[position()=2]/child::e[position()=1]", L"/descendant::a[position()=2]", L"child::a[1]/child::d[1]/preceding-sibling::c[position()=1]", L"child::a[2]/following-sibling::b[position()=1]", L"child::a[position()=2]", L"child::a[position()=last()-1]", L"child::a[position()=last()]", L"child::a[position()=1]", L"/descendant::a/child::c", L"/", L"/descendant::a", L"/child::root/child::*/child::d", L"child::b/descendant::a", L"self::root", L"/child::root/child::a/descendant-or-self::a", L"/child::root/child::a/child::c/ancestor::root", L"/child::root/descendant::a", L"/child::root/child::a/attribute::*", L"/child::root/child::a/attribute::a1", L"/child::root/child::node()", L"/child::root/child::a/child::d/child::text()", L"/child::root/child::*", L"/child::root/child::a", L"/root/a[(1+1-1)*2 div 2]", L"/child::root/child::a/ancestor-or-self::a", L"'hello'", L"1+2-3+count(/a/b/c)" }; AutoPilot *ap = NULL; int ii = 0,i; //FILE *f = NULL; //UByte *xml = NULL; //VTDGen *vg = NULL; VTDNav *vn = NULL; //struct stat s; exception e; int a,result; expr *expression = NULL; double d= 0; Try{ ap = createAutoPilot2(); declareXPathNameSpace(ap,L"test",L"jimmy"); //declareXPathNameSpace(ap,L"c",L"larry"); for(i=0;i<66;i++){ //selectXPath(ap,L"/a:b/c:d "); wprintf(L"i ==> %d \n",i); wprintf(L"input test string ==> %ls\n",tests[i]); if (selectXPath(ap, tests[i])){ //setVTDNav(ap,vn); wprintf(L"output string ===>"); printExprString(ap); wprintf(L"\n"); } else { wprintf(L" XPath parsing failed \n"); } } wprintf(L" \n\n ************** \n"); }Catch(e){ wprintf(L"%s\n",e.msg); } //freeVTDGen(vg); //freeVTDNav(vn); freeAutoPilot(ap); }
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; }