コード例 #1
0
ファイル: erase.c プロジェクト: CoolBalance/vtd-xml
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("new3.xml","wb");
			vn = getNav(vg);
			//bind(ap,vn);
			bind(ap2,vn);
			//bind4XMLModifier(xm,vn);
			//i=evalXPath(ap2);
			//printf(" i's value is %d \n",i);
			//l=getElementFragment(vn);
			//ef = getElementFragmentNs(vn);
			//writeFragmentToFile(ef,f1);
			//fclose(f1);
			
			while( (i=evalXPath(ap2))!=-1){
				//insertAfterElement4(xm,ef);
				//insertAfterElement3(xm,vn->XMLDoc,(int)l,(int)(l>>32));
				printf(" i's value is %d \n",i);
				overWrite(vn,i+1,"",0,0);
			}
			fwrite(vn->XMLDoc+vn->docOffset,sizeof(UByte),vn->docLen,f1);
			//output2(xm,"d:/new3.xml");
			fclose(f1);
			free(vn->XMLDoc);
			freeVTDNav(vn);
		}
		freeElementFragmentNs(ef);
		freeXMLModifier(xm);
		freeAutoPilot(ap);
		freeAutoPilot(ap2);
		freeVTDGen(vg);
		
	}Catch(e){
		printf("exception !!!!!!!!!!! \n");
	}
}
コード例 #2
0
ファイル: xpath.c プロジェクト: IgorBabalich/vtd-xml
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;
}
コード例 #3
0
ファイル: erase.c プロジェクト: IgorBabalich/vtd-xml
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;
}
コード例 #4
0
ファイル: insertAttr.c プロジェクト: IgorBabalich/vtd-xml
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;
}
コード例 #5
0
ファイル: indexReader.c プロジェクト: IgorBabalich/vtd-xml
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;
}
コード例 #6
0
EIF_POINTER evx_create_xpath_query (Exception_handlers_t *p_handlers, EIF_POINTER a_xpath)

{
    UCSChar *xpath = (UCSChar *)a_xpath;
    exception e;
    AutoPilot *result = NULL;
    Try {
        result = createAutoPilot2();
        selectXPath(result, xpath);
    }
    Catch (e) {
        // manual garbage collection here
        freeAutoPilot(result);
        raise_eiffel_exception (p_handlers, &e);
    }
    return (EIF_POINTER)result;
}
コード例 #7
0
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;
}
コード例 #8
0
ファイル: makeTemplate.c プロジェクト: IgorBabalich/vtd-xml
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;
}
コード例 #9
0
ファイル: xpathTest.c プロジェクト: IgorBabalich/vtd-xml
    void translateTest() 
    { 

        AutoPilot* ap = createAutoPilot2();

		if(selectXPath(ap,L"translate('12:30','30','45')"))
		{
			UCSChar* s = evalXPathToString(ap);
			assert(wcscmp(s, L"12:45") == 0);    

			free(s);
		}

		if(selectXPath(ap,L"translate('12:30','0123','abc')"))
		{
			UCSChar* s = evalXPathToString(ap);
			assert(wcscmp(s, L"bc:a") == 0);    

			free(s);
		}

		if(selectXPath(ap,L"translate('','','abc')"))
		{
			UCSChar* s = evalXPathToString(ap);
			assert(wcscmp(s, L"") == 0);    

			free(s);
		}

		if(selectXPath(ap,L"translate('12:30','33','3bc')"))
		{
			UCSChar* s = evalXPathToString(ap);
			assert(wcscmp(s, L"12:30") == 0);    

			free(s);
		}

		freeAutoPilot(ap);

	}
コード例 #10
0
ファイル: stats.c プロジェクト: CoolBalance/vtd-xml
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;
}	
コード例 #11
0
ファイル: vtd-xml.c プロジェクト: IgorBabalich/vtd-xml
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);
}
コード例 #12
0
void evx_free_xpath_query (EIF_POINTER a_xpath_query)
{
    freeAutoPilot ((AutoPilot *)a_xpath_query);
}
コード例 #13
0
ファイル: RSSReader.c プロジェクト: IvwsIgeMq/libsg
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;
}