Create data in XML format

We can create data to load into the database with the Data Load utility in an XML formatted file. This XML file must follow a specific XML format, which is similar in structure and content to the supported CSV format for loading catalog data.


Before starting

Ensure that we are familiar with the following topics: File format for Data Load input files, and Data Load utility CSV column and XML element definitions.


Task info

If you choose to create and use an XML formatted file, ensure that your file uses the CSV column names as the XML element names and uses a CSV-like file structure. Your file must also specify a keyword to associate the business object we are loading with a mediator and separate individual objects of a business object type within different elements. We must also configure the utility to use the XML data reader instead of the CSV data reader which is the default data reader. For more information about configuring the XML data reader, see Configure the XML data reader. The following code is an example of an XML file we use to upload catalog data; this example uploads two sales catalogs:

Do not change the first or second line in your XML file, or your data might not load correctly to the database. Use the remaining lines to add your business object information.


Procedure

  1. Open an XML or text editor.

  2. In the first line of your file, add the following code to define your file as an XML file:

      <?xml version="1.0" encoding="UTF-8"?>

  3. After the line that defines your file as an XML file, specify an element for the business object type that we are loading information about. We must specify this object type in the root element for our file by specifying the keyword for the business object. In this element, we must include an element name that distinguishes your root element from other elements within your file. This root element must be specified with the following format:

      <?xml version="1.0" encoding="UTF-8"?>
      <elementName loadItemName="keyword">
      </elementName>

    Where elementName is the distinguishing name for the root element, and keyword is the keyword used to identify the business object type that we are loading. For example, the following element is used to specify that a file contains catalog data.

      <?xml version="1.0" encoding="UTF-8"?>
      <CatalogObjects loadItemName="Catalog">
      </CatalogObjects>

    Note: The loadItemName declaration is required in files that are being upload with Management Center and optional for files that are loaded with the Data Load utility. As a best practice, include this declaration. By including the loadItemName declaration, your file can be loaded with both the Data Load utility or Management Center without requiring you to add the loadItemName declaration later. When we are specifying a keyword, select one of the following keywords. These keywords are case-sensitive, so ensure that you type the keyword exactly as shown:

  4. Following the line that defines the object type that your loading, specify the object that we are loading. Specify the object within an element that is nested within your root element. For example,

      <?xml version="1.0" encoding="UTF-8"?>
      <CatalogObjects loadItemName="Catalog">
        <Catalog>
        </Catalog>
      </CatalogObjects>

  5. Add the information for the object that we are loading. We can add this information as elements or as attributes in the element that specifies the object that we are loading. These attributes or elements must use the specific XML element name for the object. These names are the same as the CSV column names and are case-sensitive. We must enter these names exactly as they appear in the appropriate CSV column and XML element definitions topic. If we are adding custom information, we must enter the attribute or element names to be the same as the name in the corresponding mediator that maps the information to the correct location in the business object noun.

    • If we are adding your object information in XML elements, nest these elements within the object element you defined in the previous step. For example:

        <Catalog>
          <Identifier>Spring Fashions</Identifier>
          <MasterCatalog>FALSE</MasterCatalog>
          <Description>Spring Fashions</Description>
          <Name>Spring Fashions</Name>
          <ShortDescription>Spring Fashions</ShortDescription>
          <LongDescription>Fashions for the Spring season</LongDescription>
        </Catalog>

    • If we are adding your object information as attributes, these XML attributes must be included in the following format:

        <object attribute="attribute_value"> 

      Where object is the object that we are loading, and attribute is the name of the attribute that we are loading. For example,

        <Catalog Identifier="Spring Fashions">

    We can also include an element or attribute that specifies the sequence or delete value for the object. For example,

    • Attribute

        <CatalogEntry Sequence="1.0"  Delete="0">

    • Element

        <Delete>0</Delete>

    We can set the delete value to be 1 or 0. If you set the value to 1, then the object is deleted. If you specify the value as 0, or omit the value, the value defaults to 0 and no deletion occurs.

    Note: Working with element and attribute values:

    We can use either elements or attributes to add data to be loaded. Typically, they are loaded the same by using either method. However, they are loaded differently when the value is empty. For example, for a catalog entry, we can specify the Name use element:

      <CatalogEntry>
      <Name>Spring Fashions</Name>
      </CatalogEntry>

    Or, we can use an attribute:

      <CatalogEntry Name="Spring Fashions">
      </CatalogEntry>

    The preceding samples are equivalent when loading. However, if the value for the Name is empty, it is handled differently by the XML handler. That is, the following samples are handled differently:

      <CatalogEntry>
      <Name></Name>
      </CatalogEntry>

      <CatalogEntry Name="">
      </CatalogEntry>

    By default, all elements with empty values are treated as null. However, attributes with empty values are treated as empty values. That is, the value is null in the database if we use an element for Name, and the value is empty in the database if we use an attribute for Name. This default behavior can be changed using the following optional configuration properties.

      ignoreEmptyElementText
      If set to false, empty elements are treated as empty values. Default is true.

      ignoreEmptyAttributeValue
      If set it to true, empty attribute values are treated as null. Default is false.

    The property can be specified under the <DataReader> element, <LoadItem> element, or <LoadOrder> element as:

      <_config:property name="ignoreEmptyElementText" value="false" />

    For more information, see Configure the XML data reader.

  6. Optional: Repeat steps 4 and 5 to add information for more objects within your file. Each object must be specified within a separate XML element. Do not nest your objects deeply. Nest the element for each object we are including directly within your root element. For example, to include three catalog objects within a file, your file can resemble the following code:

      <CatalogObjects loadItemName="Catalog">
        <Catalog>
          <Identifier>Spring Fashions</Identifier>
          <MasterCatalog>FALSE</MasterCatalog>
          <Description>Spring Fashions</Description>
          <Name>Spring Fashions</Name>
          <ShortDescription>Spring Fashions</ShortDescription>
          <LongDescription>Fashions for the Spring season</LongDescription>
        </Catalog>
        <Catalog Delete="0">
          <Identifier>Summer Fashions</Identifier>
          <MasterCatalog>FALSE</MasterCatalog>
          <Description>Summer Fashions</Description>
          <Name>Spring Fashions</Name>
          <ShortDescription>Summer Fashions</ShortDescription>
          <LongDescription>Fashions for the Summer season</LongDescription>
        </Catalog>
        <Catalog Delete="0">
          <Identifier>Fall Fashions</Identifier>
          <MasterCatalog>FALSE</MasterCatalog>
          <Description>Fall Fashions</Description>
          <Name>Spring Fashions</Name>
          <ShortDescription>Fall Fashions</ShortDescription>
          <LongDescription>Fashions for the Fall season</LongDescription>
        </Catalog>
      </CatalogObjects>

  7. Save and close your file. Your completed file can resemble the following code:

      <?xml version="1.0" encoding="UTF-8"?>
      <CatalogObjects loadItemName="Catalog">
        <Catalog>
          <Identifier>Spring Fashions</Identifier>
          <MasterCatalog>FALSE</MasterCatalog>
          <Description>Spring Fashions</Description>
          <Name>Spring Fashions</Name>
          <ShortDescription>Spring Fashions</ShortDescription>
          <LongDescription>Fashions for the Spring season</LongDescription>
        </Catalog>
        <Catalog Delete="0">
          <Identifier>Summer Fashions</Identifier>
          <MasterCatalog>FALSE</MasterCatalog>
          <Description>Summer Fashions</Description>
          <Name>Spring Fashions</Name>
          <ShortDescription>Summer Fashions</ShortDescription>
          <LongDescription>Fashions for the Summer season</LongDescription>
        </Catalog>
        <Catalog Delete="0">
          <Identifier>Fall Fashions</Identifier>
          <MasterCatalog>FALSE</MasterCatalog>
          <Description>Fall Fashions</Description>
          <Name>Spring Fashions</Name>
          <ShortDescription>Fall Fashions</ShortDescription>
          <LongDescription>Fashions for the Fall season</LongDescription>
        </Catalog>
      </CatalogObjects>


Results

You created XML files in a suitable format for loading into the database with the Data Load utility. When you load your XML file, the business object keyword and the element names for the object information are interpreted. The keyword and element names are not included in the database with the object information.