[Home] [System] [Publication] [Download] [Documentation] [People]
OrientX 3.0 is released
 

Programming with OrientX3.0

    There are two approaches to get to know OrientX3.0: graphical user interface and programmable. The important part is the xml document management. The dataset in OrientX acts the same role as the database in relation database. OrientX manages XML data by means of data set. And a data set may contain serveral xml documents.
    So the first step of programming with OrientX is to create data set. The picture "Basic OrientX Programming Flow" in the right shows the steps to execute XQuery on documents in OrientX. So if you know how to manage the dataset in the following aspects, you will konw OrientX very well. Now let's take a look at the programmable usage:

Basic OrientX Programming Flow

Creating a dataset

    Dataset plays an important role in OrientX. All data is organised by dataset including xml data, schema information and so on. In OrientX3.0, the dataset is not binded to the schema. So when you create an dataset, you register a dataset in the global control information. Remmeber that if there has been a dataset called "bib", it will return -1.Just copy the code to your application and make a little modification:

	 try
	{
    	CExecuteEngine::Initialize();//initial all the running environment
    	if(CExecuteEngine::CreateDataSet("bib") == -1)
    	{//call the create dataset method
    	cout << "There is an error occur in creating a dataset!" << endl;
    	}
	}
	catch(NxdbException& e)
	{
		e.Print();
		return 0;
	}
		

    Then, you will create a dataset named "bib".

 

Deleting a dataset

    Once you want to delete an dataset, call the corresponding method and then it will be done. But, remmeber that if the dataset is not available, the method will return -1.

	 try
	{
    	CExecuteEngine::Initialize();//initial all the running environment
    	if(CExecuteEngine::DropDataSet("bib") == -1)
    	{//call the delete dataset method
    	cout << "There is an error occur in deleting a dataset!" << endl;
    	}
	}
	catch(NxdbException& e)
	{
		e.Print();
		return 0;
	}
		

    Then, you will delete the dataset named "bib".

 

Registering a schema

    Since in the new version3.0 the schema is independent with the dataset. So we put the schema management module aside in the originall version and manage the schema information individually. All the schema information is also organised in the form of dataset. If the schema has existed yet, you will not create the new schema successfully. The method will return -1 to inform you that an error has occured.

	 try
	{
    	CExecuteEngine::Initialize();//initial all the running environment
		//call the method, the former parameter means the schema URL in the system,
		//and the later represents the physical location of the schema
    	if(CExecuteEngine::RegisterSchema("http://xmark",
		"F:\\data\\xmldata\\xmark\\xmark.xsd") == -1)
    	{//call the register dataset method
    	cout << "There is an error occur in registering a schema!" << endl;
    	}
	}
	catch(NxdbException& e)
	{
		e.Print();
		return 0;
	}
		

    Then, you will register a schema named "http://xmark".

 

Deleting a schema

    Once you want to delete an schema, call the corresponding method and then it will be done. But, remmeber that if the schema is not available, the method will return -1.

	 try
	{
    	CExecuteEngine::Initialize();//initial all the running environment
		//Here the parameter means the URL of the deleted schema
    	if(CExecuteEngine::DeleteSchema("http://xmark") == -1)
    	{//call the delete dataset method
    	cout << "There is an error occur in deleting a schema!" << endl;
    	}
	}
	catch(NxdbException& e)
	{
		e.Print();
		return 0;
	}
		

    Then, you will delete the schema whose URL is "http://xmark".

 

Importing a document

    Once the dataset is available, you can import a document. The document is attached to a dataset. And when you import a document, make sure to specify a schema URL which the document should conform to. Use the code below to import a document. If the method returns -1, then an error occurs. So make sure that the document name is not repeatable.

	 try
	{
    	CExecuteEngine::Initialize();//initial all the running environment
		//Here the first parameter means the dataset where the document will be import
		//the second means the import document's physical location
		//the third means the URL of the deleted schema
		//the fourth means the storage mode including DEB,DSB,CEB and CSB, and so on...
		//the fifth means the encode method
		if(CExecuteEngine::CExecuteEngine::ImportDoc("xmark",
				"F:\\data\\xmldata\\xmark\\auctions6.xml",		 
				"http://xmark",DEBMode,REGION32ENCODER) == -1)
    	{//call the delete dataset method
    	cout << "There is an error occur in importing an xml doc!" << endl;
    	}
	}
	catch(NxdbException& e)
	{
		e.Print();
		return 0;
	}
		

    Then, you will import the corresponding document.
    Note: After this, the document name registered in the system has been "auctions6.xml" and not the full path.

 

Exporting a document

    Call the export document function and you will get an xml document copy. Given two parameters to specify a document, the system will export a document easily.

	 try
	{
    	CExecuteEngine::Initialize();//initial all the running environment
		//Here the first parameter means the dataset whic the document belongs to
		//the second means the name of the document(here is the name and not the full path)
		//the third means the location of the document to export
		if(CExecuteEngine::ExportDoc("xmark", "xmark5.xml",
			"D:\\xmldata\\xmark\\csb_xmark5.xml") == -1)
    	{//call the delete dataset method
    	cout << "There is an error occur in exporting an xml doc!" << endl;
    	}
	}
	catch(NxdbException& e)
	{
		e.Print();
		return 0;
	}
		

    Then, you will export the corresponding document.

 

Deleting a document

    If you want to delete a document, then call the corresponding method called "DropDoc". If the return value equals -1, then the delete fails.

	 try
	{
    	CExecuteEngine::Initialize();//initial all the running environment
		//Here the first parameter means the dataset whic the document belongs to
		//the second means the name of the document(here is the name and not the full path)
		if(CExecuteEngine::DropDoc("xmark","auctions6.xml") == -1)
    	{//call the delete dataset method
    	cout << "There is an error occur in deleting an xml doc!" << endl;
    	}
	}
	catch(NxdbException& e)
	{
		e.Print();
		return 0;
	}
		

    Then, deleting a document is done.

 

Excute an XQuery

    Here, we put the XQuery sentences in an input file. Here the XQuery senctences including the update sentences such as insert,delete,rename. Once the xquery is done, you can export the document and see whether it is done.

	 try
	{
    	CExecuteEngine::Initialize();//initial all the running environment
		char* inputfile = "D:\\xmldata\\xmark\\testquery\\j1.xq";
		char* outputfile = "D:\\xmldata\\xmark\\result\\j1.result";

		//Here the first parameter means the file including the XQuery sentences
		//the second means the output the XQuery
		CExecuteEngine::ExecXQuery(inputfile, outputfile, true,false);	
	}
	catch(NxdbException& e)
	{
		e.Print();
		return 0;
	}
		

    Then, the XQuery is done. Open the result and you will see it.

WAMDM, Renmin University of China, All Rights Reserved OrientXRUC AT gmail.com Last Updated : 2007/11/22