Microsoft KB Archive/295669

= How To Persist a Purchase Order from an Orderform Dictionary to an XML File Conforming to an XML Schema =

Article ID: 295669

Article Last Modified on 7/2/2004

-

APPLIES TO


 * Microsoft Commerce Server 2000 Standard Edition

-



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(&quot;Commerce.DictionaryXMLTransforms&quot;)

' This is path information depending on your environment. sFilePath = &quot;D:\Inetpub\wwwroot\retail\poschema.xml&quot; 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(&quot;Scripting.FileSystemObject&quot;) Set MyFile = fso.CreateTextFile(&quot;c:\PO.xml&quot;, 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:  Unpup the retail site. From the Tutorial folder on the Commerce 2000 CD, import Booksful.xml or Hardwarefull.xml. Add shipping methods. To do this, start BizDesk. On the Orders menu, click Shipping Methods, and then click New. From a command prompt, type pipeeditor to run the Pipeline Editor, and then open C:\Inetpub\Wwwroot\Retail\Pipeline\Checkout.pcf. 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.  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(&quot;Commerce.DictionaryXMLTransforms&quot;)

' Path information depending on your environment. sFilePath = &quot;D:\Inetpub\wwwroot\retail\poschema.xml&quot;  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(&quot;Scripting.FileSystemObject&quot;) Set MyFile = fso.CreateTextFile(&quot;c:\PO.xml&quot;, True) MyFile.Write (oOrderFormXML.xml) MyFile.Close MSCSExecute = 1

End Function </li> Save the pipeline and the code in the Scriptor component.</li> 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.</li></ol>

<div class="references_section">