Using XMS: It really is this simple!

By xmlnative


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

Leave a Reply