XML Vol 2 Issue 4 - pg.62
Mission Impossible XML (MI-XML), by John Thompson And David Reis

Download associated word file.

Listing  1

Public Function StoreEntityDefinition(strEntityDefinition As String, strID As String) As Boolean
'   Synopsis:       Function to store an Entity Definition
                  document in the XML Server
'   Author:         David Reis CROSSMARK, Inc.
'   Date Written:   12/18/2001
'   Parameters:
'   strEntityDefinition - string containing the XML of the
   Entity Definition
'   strID - string containing the GUID for the Entity
   Definition.  This will be used as the file name the
   document is stored as.
'   StoreEntityDefinition - (R) Boolean representing
   success or failure in storing the Entity Definition
'   Description :   This function takes a string
    containing the XML for a new Entity Definition,
    saves it as a file to the temp directory, stores
    the file to the XML Server, parses the results, and
    deletes the temp file.
'    Revision History:
   Dim str_Results As String
   Dim lng_ResultLength As Long
   Dim str_TempFolder As String
   Dim str_TempFile As String
   Dim fs_FileScripting As Scripting.FileSystemObject
   Dim m_obj_NeoCore As NEOCOREAPI2Lib.NeoCoreAPI
   Dim obj_TextFile As Scripting.TextStream
   Dim str_Remaining As String

   'The server running the NeoCore XML server and
     the port
   'on which it is listening are the only connection
   'parameters required.
   If Len(Me.Server) > 0 And Me.Port > 0 Then

       'With the current API, in order to store a new
         document in the XML
       'repository, it must exist as a file.  In this
         function, we create
       'a temporary file in the Windows Temp folder.
         Once the document has
       'been stored, we will delete the file. In a future
         version of the API,
       'we can simply pass a string to the storeXML
         function and remove this.

       'This calls a Windows API function that returns
         the path to the
       'Windows Temp folder.
       str_TempFolder = GetTmpPath

       If Len(str_TempFolder) > 0 And Len(strID) > 0 Then

           'The name of the temporary file will be the
             GUID of the Entity
           str_TempFile = str_TempFolder & "\" & strID &

           'The string containing the XML is written to a
             file using the
           'Microsoft Scripting Runtime's FileSystem
           Set fs_FileScripting = New

           'Create the file
           Set obj_TextFile = fs_FileScripting.CreateTextFile
(str_TempFile, True)

           'Write the XML to the file
           obj_TextFile.WriteLine (strEntityDefinition)

           'Close the file

           Set obj_TextFile = Nothing

           'Initialize the results
           str_Results = ""

           'In NeoCore's API, the client is expected
             to have preallocated
           'the memory required to store the results of
             the operation.
           'That sizing should be based upon maximum
             result sizes that
           'the client expects to encounter in use
           lng_ResultLength = 10000

           'Instantiate the Type Library we wrote as a
             wrapper for NeoCore's
           Set m_obj_NeoCore = New

           'This code calls a C++ Type Library that was
            written as a COM wrapper
           'for NeoCore's API.  Calls cannot be made
            directly to the API from Visual
           'Basic so we wrote the Type Library to get
            around this limitation
           Call m_obj_NeoCore.Store(str_Results,
            lng_ResultLength, Me.Server, Me.Port _
                           , "", str_TempFile, "", "")

           'Set the Type Library to nothing
           Set m_obj_NeoCore = Nothing

           'unload the DLL
           Call CoFreeUnusedLibraries

           'Delete the temporary file
           Call fs_FileScripting.DeleteFile(str_TempFile,

           'Call a function to parse the results and
            determine if there were errors
           Call ParseXMLResults(str_Results)

           'Check for errors
           If ErrorCount = 0 Then
               StoreEntityDefinition = True
               StoreEntityDefinition = False
           End If
           StoreEntityDefinition = False
       End If
   End If
End Function