Archive for December, 2006

Using XMS: It really is this simple, Part II

December 14, 2006

Retrieval of XML data using XMS

As in the storage example, the retrieval of XML data is centered
Around these three lines of code

// create and execute XML Query command
thisXMSCmd = new XmsCommand(“query”, thisXMSCon);
thisXMSCmd.Parameters.Add(“query”, mySB.ToString());
thisXMSCmd.ExecuteNonQuery();

where mySB contains an XPath query. In this instance
the XPath query is

/ND/StaffingOrganization[Organization/OrganizationId/IdValue='333-99-1234']

and will work with the XML store in the ‘Using XMS: It really is this simple’

Here’s all the code, Have Fun!

using System;
using System.Text;
using System.Data;
using Xpriori.XmsDataProvider;

namespace RetrieveXMLConApp.cs
{
  /// <summary>
  /// Summary description for RetrieveXMLCon.
  /// </summary>
  public class RetrieveXMLCon
  {
    static XmsConnection thisXMSCon;
    static XmsCommand thisXMSCmd = null;

    static void Main(string[] args)
    {
      try
      {
        // get a connection to XMS at “localhost” on default port 7700
        thisXMSCon = new XmsConnection(“localhost;7700;” + “Administrator” + “;” + “password”);
        if ( thisXMSCon != null )
        {
          thisXMSCon.Open();
          if( thisXMSCon.State == ConnectionState.Open )
          {
            // create an XML String to store
            StringBuilder mySB = new StringBuilder(“”);
            mySB.Append(“/ND/StaffingOrganization[Organization/OrganizationId/IdValue='333-99-1234']“);

            // create and execute XML Query command
            thisXMSCmd = new XmsCommand(“query”, thisXMSCon);
            thisXMSCmd.Parameters.Add(“query”, mySB.ToString());
            thisXMSCmd.ExecuteNonQuery();

            // output results to console
            Console.WriteLine(thisXMSCmd.Results);
            Console.WriteLine(“”);

            // close the XMS connection
            thisXMSCon.Close();
          }
        }
        else
        {
          Console.WriteLine(“Invalid UserName or Password or XMS is not started”);
        }
        Console.WriteLine(“Application Exiting”);
        Console.WriteLine(“”);

      }
      catch (ApplicationException ex)
      {
        String msg = “Application error:” + ex.Message;
        Console.WriteLine(msg);
      }
    }

  }
}