Archive for the ‘XMS Example’ Category

Searching for a sub-string within an XML Node

February 20, 2007

XMS makes it easy to search for a sub-string within a node.

By adding asterisks around an XPath search string, XMS will look
through the entire node looking to match the sub-string.

 

For example using the XML nodes below, the XPath expression:

 /ND/Catalog/CD[Company=*'Records'*] 

will return both the first and last nodes.

 

Happy Searching!

 

 catalog-cd.JPG

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);
      }
    }

  }
}

Using XMS: It really is this simple!

November 27, 2006


Storage of XML data using XMS.

XMS is able to receive any well-formed XML document you want to throw at it, at any time.  The following code example demonstrates this capability.  The center of the example is three lines of code.

    thisXMSCmd = new XmsCommand(“storestring”, thisXMSCon);
    thisXMSCmd.Parameters.Add(“xml”, mySB.ToString());
    thisXMSCmd.ExecuteNonQuery();

First, ‘XmsCommand’ creates an XMS command to store a string formatted with XML data.  Next, ‘Parameters.Add’ attaches the XML string to the XmsCommand. And finally, ‘ExexuteNonQuery’ sends the XML data into the XMS database.

The key here is that XMS takes advantage of the XML’s self describing nature to store the XML with out first having to construct a database table or define the table’s columns.

To run this example, download XMS

Get it from CNET Download.com!

and the XMS.NET API 2

Get it from CNET Download.com!

Be sure to create a reference to the XMSDataProvider located at:
“C:\Program Files\Xpriori\XMS.NET API V2.0\XMSCSharpTestApplication\XmsDataAdapter.dll”

and change “YourAdminPassword” to the Administrators Password.

If you have any question don’t hesitate to Email me at dspalding@xpriori.com

The example is from HR-XML StaffingOrganization.xml

XMS Store XML Example

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

namespace StoreXMLConApp
{
  /// <summary>
  /// Summary description for StoreXMLCon.
  /// </summary>
  public class StoreXMLCon
  {
    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” + “;” + “yourAdminPassword”);
        if ( thisXMSCon != null )
        {
          thisXMSCon.Open();
          if( thisXMSCon.State == ConnectionState.Open )
          {
            // create an XML String to store
            StringBuilder mySB = new StringBuilder(“”);
            mySB.Append(“<StaffingOrganization typeOfOrganization=’Customer’ xml:lang=’en-us’>”);
            mySB.Append(“   <Organization>”);
            mySB.Append(“      <OrganizationName>Joe Ricci Restaurant</OrganizationName>”);
            mySB.Append(“      <OrganizationId>”);
            mySB.Append(“         <IdValue>333-99-1234</IdValue>”);
            mySB.Append(“      </OrganizationId>”);
            mySB.Append(“   </Organization>”);
            mySB.Append(“</StaffingOrganization>”);

            // create and execute XML storestring command
            thisXMSCmd = new XmsCommand(“storestring”, thisXMSCon);
            thisXMSCmd.Parameters.Add(“xml”, 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);
      }
    }
  }
}