How To Persist a Purchase Order from an Orderform Dictionary to an XML File Conforming to an XML Schema (295669)



The information in this article applies to:

  • Microsoft Commerce Server 2000

This article was previously published under Q295669

SUMMARY

In certain circumstances, you may want to persist a purchase order from an OrderForm dictionary to an XML file that conforms to a specific XML schema. For example, after you complete a purchase order in Commerce Server 2000, if you want to write the purchase order to an XML file and drop it to a folder for BizTalk Server 2000 or Microsoft Message Queuing (MSMQ) components to pick up or for later use, you need to persist the OrderForm object to an XML file.

MORE INFORMATION

Commerce Server 2000 has two pipeline components, MakePO and POToFile, that can persist a purchase order to a file, but they cannot save the purchase order to an XML file that has a schema. However, the Commerce Server 2000 DictionaryXMLTransform component can save the purchase order to an XML file that has a schema.

The following Microsoft Visual Basic code sample converts the OrderForm object to a POschema-compatible XML file that is located at D:\Inetpub\Wwwroot\Retail\Poschema.xml.
'Read the XML from Poschema.xml using Commerce.DictionaryXMLTransforms.	

Set oXMLTransforms = CreateObject("Commerce.DictionaryXMLTransforms")

             ' This is path information depending on your environment.
sFilePath =  "D:\Inetpub\wwwroot\retail\poschema.xml" 
Set oXMLSchema = oXMLTransforms.GetXMLFromFile(sFilePath) 

' Transform PO into XML using Commerce.DictionaryXMLTransforms.
Set oOrderformXML = oXMLTransforms.GenerateXMLForDictionaryUsingSchema(OrderForm, oXMLSchema)

' Now write the XML to a file named C:\PO.xml.
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\PO.xml", True)
MyFile.Write (oOrderFormXML.xml)
MyFile.Close
Set MyFile = Nothing
Set fso = Nothing
				
NOTE: There are various ways to apply this code. You can use it in an ASP page, or you can use it in a Scriptor component in a Commerce pipeline.

To persist the purchase order in a Scriptor component in the checkout pipeline, follow these steps:
  1. Unpup the retail site.
  2. From the Tutorial folder on the Commerce 2000 CD, import Booksful.xml or Hardwarefull.xml.
  3. Add shipping methods. To do this, start BizDesk. On the Orders menu, click Shipping Methods, and then click New.
  4. From a command prompt, type pipeeditor to run the Pipeline Editor, and then open C:\Inetpub\Wwwroot\Retail\Pipeline\Checkout.pcf.
  5. Insert a Scriptor component before the RecordEvent component. To do this, select and then right-click the RecordEvent component, click Insert Component, and click Before. In the Choose Component menu, select Scriptor.
  6. Right-click the Scriptor component that you just inserted and click Properties. Click Edit, and then paste the following code into the Scriptor component:
    function MSCSExecute(config, orderform, context, flags)
    
        ' This VB code sample converts the OrderForm 
        ' to a POschema compatible XML file.
        '
        ' Note: Make sure you have the correct path for poschema.xml. 
        ' It is in \Wwwroot\Retail by default.
        ' In this code it is at D:\Inetpub\Wwwroot\Retail\Poschema.xml.
        ' The output file for this example is c:\po.xml.
    
        'Read the XML from POschema.xml using Commerce.DictionaryXMLTransforms.	
    
        Set oXMLTransforms = CreateObject("Commerce.DictionaryXMLTransforms")
    
        ' Path information depending on your environment.
        sFilePath =  "D:\Inetpub\wwwroot\retail\poschema.xml" <BR/>
        Set oXMLSchema = oXMLTransforms.GetXMLFromFile(sFilePath) 
    
        ' Transform PO into XML using Commerce.DictionaryXMLTransforms.
    
        Set oOrderformXML = oXMLTransforms.GenerateXMLForDictionaryUsingSchema(OrderForm, oXMLSchema)
    
        ' Now write the XML to a file. 
    
        ' Dim fso, MyFile
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set MyFile = fso.CreateTextFile("c:\PO.xml", True)
        MyFile.Write (oOrderFormXML.xml)
        MyFile.Close
        MSCSExecute = 1
    
    End Function
    					
  7. Save the pipeline and the code in the Scriptor component.
  8. Log on to the retail site. Register a user and login, add some products to your basket, and then check out. A file is generated in C:\Po.xml.

REFERENCES

For more information on Commerce.DictionaryXMLTransforms, see the Commerce Server 2000 online documentation.

Modification Type:MinorLast Reviewed:7/2/2004
Keywords:kbhowto KB295669