Beispiel #1
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;

}
Beispiel #2
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;
}
Beispiel #3
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);
	}