Jaa


How to Generate an XSD File

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

To generate an XSD file for the catalog schema, you export a file with the FormatType property of the ExportOptions parameter set to CatalogFormatXsd. If you specify this attribute, other properties such as CatalogsToExport and PropertiesToExport are ignored. An XSD file is generated.

Aa545319.alert_caution(en-US,CS.70).gifImportant Note:

Do not create a multilingual property "Name" in the category definition. This causes a conflict with existing properties, and the export will fail.

To generate an XSD file

  1. Create a CatalogExportOptions object and set the FormatType property to CatalogFormatXsd.

  2. Use one of the ExportXml methods on the CatalogContext object to start the export operation.

  3. Monitor the status of the export operation and look for errors by using the Status property of the ExportProgress object returned by the ExportXml method.

Example

This example describes how to generate an XSD file. It generates the file "testfile.xml" in the temp directory of this computer.

public static void ExportCatalog(CatalogContext context, string catalogName)
{
    // 3-second refresh interval.
    const int RefreshInterval = 3000;

    // Create CatalogExportOptions and set the options 
    // for the export operation.
    CatalogExportOptions exportOptions = new CatalogExportOptions();
    exportOptions.FormatType = CatalogExportFormatType.CatalogFormatXsd;
    exportOptions.Synchronous = false;
    // The XSD will be written to an XML file "testfile" in the 
    // temp directory on this computer.
    string fileName = Path.GetTempPath() + @"\testfile.xml";

    // Call ExportXML to generate the XSD. Monitor the progress of the operation.
    ExportProgress progress = context.ExportXml(exportOptions, fileName);
    while (progress.Status == CatalogOperationsStatus.InProgress)
    {
        System.Threading.Thread.Sleep(RefreshInterval);
        progress.Refresh();
    }
    // If the export operation failed, write the errors to the console.
    if (progress.Status == CatalogOperationsStatus.Failed)
    {
        foreach (CatalogError error in progress.Errors)
        {
            Console.WriteLine(string.Format("Line number: {0} Error message: {1}",
                error.LineNumber, error.Message));
        }
    }
}

See Also

Other Resources

Exporting Catalog Data by Using the Catalog API

What Are the Export Options?