Ejemplo n.º 1
0
int main(){
	int i = 0,t,result,len,count=0;
	UCSChar *tmpStr = NULL;
	char* xml = "<root>good</root>";
	
	VTDNav *vn = NULL;
	try{
		VTDGen vg;
		vg.setDoc(xml,strlen((const char*)xml));
		vg.parse(true);
		vn = vg.getNav();
		i = vn->getText();
		tmpStr = vn->toString(i);
		wprintf(L" text value is %s\n",tmpStr);
		delete(tmpStr);
		len=strlen("bad");
		vn->overWrite(i,"bad",0,len);
		tmpStr = vn->toString(i);
		wprintf(L" text value is %s\n",tmpStr);
		delete(tmpStr);
		// remember C has no automatic garbage collector
		// needs to deallocate manually.
		delete(vn);
	}
	catch (...) {
		// manual garbage collection here
		delete (vn);
	}
	return 0;
}
Ejemplo n.º 2
0
int main(){

	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;

		VTDGen vg;// = createVTDGen();
		AutoPilot ap; // = createAutoPilot2();
		AutoPilot ap2; //= createAutoPilot2();
		XMLModifier xm; //= createXMLModifier();
		ap.selectXPath(L"(/*/*/*)[position()>1 and position()<4]");
		ap2.selectXPath(L"/*/*/*");
		if (vg.parseFile(true,"c:/xml/soap2.xml")){
			//FILE *f1 = fopen("d:/new3.xml","wb");
			vn = vg.getNav();
			ap.bind(vn);
			ap2.bind(vn);
			xm.bind(vn);
			ap2.evalXPath();
			ef = vn->getElementFragmentNs();

			while( (i=ap.evalXPath())!=-1){
				xm.insertAfterElement(ef);
				printf(" index %d \n",i);
			}
			//fwrite(vn->XMLDoc+vn->docOffset,sizeof(UByte),vn->docLen,f1);
			xm.output("c:/xml/new3.xml");
			//fclose(f1);
			delete (vn->getXML());
			delete (vn);
		}
		delete(ef);
		/*freeXMLModifier(xm);
		freeAutoPilot(ap);
		freeAutoPilot(ap2);
		freeVTDGen(vg);*/

	}catch(...){
		printf("exception !!!!!!!!!!! \n");
	}
	return 0;

}
Ejemplo n.º 3
0
// test book mark
int main(){
	VTDGen *vg = new VTDGen();
	AutoPilot *ap = new AutoPilot();
	if (vg->parseFile(true,"c:\\xml\\oldpo.xml")){
		VTDNav *vn;
		try{
			vn = vg->getNav();
			ap->bind(vn);
			BookMark *bm = new BookMark();
			bm->bind(vn);
			ap->selectXPath(L"/purchaseOrder/items/item[@partNum='872-AA']/USPrice[.>100]");
			//ap->selectXPath(L"/purchaseOrder/items/item[@partNum='872-AA']");
			ap->printExprString();
			printf("\n");
			int i=-1;
			while((i=ap->evalXPath())!=-1){
				// remember the cursor position after navigation using xpath
				bm->recordCursorPosition(vn); //recordCursorPosition2(bm) also works.
				printf(" index val ==> %d \n", vn->getCurrentIndex());
			}
			vn->toElement(ROOT); // set the cursor to root
			printf(" index val ==> %d \n", vn->getCurrentIndex());
			bm->setCursorPosition(); // set the cursor back to remembered position
			printf(" index val ==> %d \n", vn->getCurrentIndex());
		}catch(...){
		}

		delete vn->getXML();
		delete vn;
		//delete bm;
		delete ap;
	}

	delete vg;
	return 0;
}
Ejemplo n.º 4
0
int main(){

	VTDGen vg;
	AutoPilot ap0, ap1, ap2;

	ap0.selectXPath(L"/root/a");
	ap1.selectXPath(L"/root/b");
	ap2.selectXPath(L"/root/c");
	if (vg.parseFile(false,"c:/xml/old.xml"))
	{
		VTDNav* vn = vg.getNav();
		ap0.bind(vn);
		ap1.bind(vn);
		ap2.bind(vn);


		//FileStream fos = new FileStream("new.xml", System.IO.FileMode.OpenOrCreate);
		FILE* fos = fopen("c:/xml/new.xml","wb");
		//fos.Write("<root>".getBytes());
		char *ba1, *ba2, *ba3;
		//ba0 = eg.GetBytes("
		ba1 = "<root>";
		ba2 = "</root>";
		ba3 = "\r\n";
		//fos.Write(ba1, 0, ba1.Length);
		fwrite(ba1,sizeof(char),strlen(ba1),fos);
		char* ba = (char *)vn->getXML();
		while (ap0.evalXPath() != -1)
		{
			Long l = vn->getElementFragment();
			int offset = (int)l;
			int len = (int)(l >> 32);
			fwrite(ba3,sizeof(char),strlen(ba3),fos);
			fwrite(ba+offset,sizeof(char),len,fos);
			//fos.Write(ba3,0,ba3.Length);
			//fos.Write(ba, offset, len);
		}
		ap0.resetXPath();
		while (ap1.evalXPath() != -1)
		{
			Long l = vn->getElementFragment();
			int offset = (int)l;
			int len = (int)(l >> 32);
			fwrite(ba3,sizeof(char),strlen(ba3),fos);
			fwrite(ba+offset,sizeof(char),len,fos);
			//fos.Write(ba3,0,ba3.Length);
			//fos.Write(ba, offset, len);
		}
		ap1.resetXPath();
		while (ap2.evalXPath() != -1)
		{
			Long l = vn->getElementFragment();
			int offset = (int)l;
			int len = (int)(l >> 32);
			fwrite(ba3,sizeof(char),strlen(ba3),fos);
			fwrite(ba+offset,sizeof(char),len,fos);
			//fos.Write(ba3,0,ba3.Length);
			//fos.Write(ba, offset, len);
		}
		ap2.resetXPath();
		fwrite(ba3,sizeof(char),strlen(ba3),fos);
		fwrite(ba2,sizeof(char),strlen(ba2),fos);
		fclose(fos);
		delete (vn->getXML());
		delete (vn);
		//fos.Write(ba3,0,ba3.Length);
		//fos.Write(ba2,0,ba2.Length);
	}