Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX -
Contents Index PreviousNext

Appendix I Sample C++ .NET Programs> I.1 Searching Data

I.1.3 Obtain Every Instance of Particular XML Documents

The search process performs the operations stated in I.1.1 Obtaining the Number of XML Documents that Match Search Conditions and I.1.2 Obtaining XML Documents that Match Search Conditions in a Specified Format to obtain all the data based on the filtering conditions.

The following example shows how the C++ .NET are used. It shows how all the data of applicable hotels can be retrieved based on the hotel names obtained using the operations stated in I.1.2 Obtaining XML Documents that Match Search Conditions in a Specified Format.

mark1Search Conditions

'I want to obtain detailed information about a number of the hotels in Sydney that have a vacancy on 2006/07/18.'Execute the search using the date (2006/07/18) and the location (Sydney) as search conditions. The record IDs that correspond to hotels are used to obtain detailed information.

mark1An Example of Using the APIs

The following is a sample program using the C++ .NET.

#using <mscorlib.dll>
#using <system.dll>
#using <Fujitsu.Shunsaku.dll>

using namespace System;
using namespace Fujitsu::Shunsaku;

class SampleSearchByRecordID {
public:
  static void Main( String *args __gc[] ) {
    ShunService *service = 0;

    try {
      // Create ShunService
      service = new ShunService();

      // Connect Shunsaku by specifying the host name and port number
      service->Host = "DirSvr1";
      service->Port = 33101;
      service->Connect();

      // Create ShunSearchRequirement
      ShunSearchRequirement *req = new ShunSearchRequirement();

      // Set each type of search conditions
      req->QueryExpression = "/document {/base/city == 'Sydney' AND /information/date == '2006/07/18'}";
      req->ReturnExpression = "/document/base/name/text()";
      req->ReplyNumber = 1;
      req->RequestCount = 30;

      // Specify the search condition and execute the search
      ShunResultSet *rs = service->Search( req );

      // Display the search results
      Console::WriteLine( "Number of hits  = {0}", __box( rs->HitCount ) );

      // Create ShunRecordCollection for searching data
      ShunRecordCollection *searchRecords = new ShunRecordCollection();

      // Obtain the records that correspond to the search conditions
      ShunRecordEnumerator *enumerator = rs->Records->GetEnumerator();
      while ( enumerator->MoveNext() ) {
        ShunRecord *record = enumerator->Current;
        if ( record->Data->Equals( "Hotel 1" ) ) {
          searchRecords->Add( record );
        }
      }

      // Refer detailed information if acquisition of the corresponding record is successful
      if ( searchRecords->Count > 0 ) {
        rs = service->SearchByRecordID( searchRecords );
        enumerator = rs->Records->GetEnumerator();
        while ( enumerator->MoveNext() ) {
          ShunRecord *record = enumerator->Current;
          Console::WriteLine( "[Details] = {0}", record->Data );
        }
      }

      // Close the connection to Shunsaku
      service->Disconnect();

    }
    catch ( ShunContinuousException *e ) {
      // Processing to perform if ShunContinuousException occurs
      try {
        if( service != 0 && service->State == ShunConnectionState::Open ) {
          service->Disconnect();
        }
      }
      catch ( ShunException *ex ) {
        Console::WriteLine( "Error message : {0}", ex->Message );
      }
      Console::WriteLine( "Error message : {0}", e->Message );
    }
    catch ( ShunConnectionTerminatedException *e ) {
      // Processing to perform if ShunConnectionTerminatedException occurs
      Console::WriteLine( "Error message : {0}", e->Message );
    }
  }
};

int main() {
  return SampleSearchByRecordID::Main( Environment::GetCommandLineArgs() );
}

mark1Execution Results

Number of hits       = 3
[Details] = <document>
    <base>
        <name>Hotel 1</name>
        <city>Sydney</city>
        <address>Bondi Beach</address>
        <detail>http://xxxxx.com.au</detail>
        <price>350</price>
    </base>
    <information>
        <date>2006/07/18</date>
    </information>
    <note>En-suite bathroom and toilet, two minutes' walk to train station XX</note>
</document>

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006