Generic XML Import Advanced Example

The following is an example of a more complex import document and template that uses most of the features present in a Generic XML template.

Input Document

Copy the following text to a new file and save as an XML file. Open Import Manager and select the file as the Data Source Filename and click 'Next.' Note that any number of additional items could be included by repeating the data within the Item tag.

Copy
<?xml version="1.0" encoding="utf-8"?>
<ItemLoad>
   <Items>
      <Item>
         <EAN>2700524977488</EAN>
         <PrimarySpecs>
            <ProductInformation>
               <General>
                  <ProductName>AC-UZ444</ProductName>
                  <ConsumerShortDescription>Active 3D Glasses</ConsumerShortDescription>
                  <AvailableFrom>2015-01-01 00:00:00</AvailableFrom>
               </General>
               <Variants>
                  <Name>Color</Name>
                  <Value>Gray</Value>
               </Variants>
               <Variants> 
                  <Name>Battery</Name>
                  <Value>C2</Value>
               </Variants>
               <Manuals>
                  <Manual type="ManualDE">Manual-9</Manual>
                  <Manual type="ManualEN">Manual-10</Manual>
               </Manuals>
            </ProductInformation>
         </PrimarySpecs>
         <SyncProtocols>
            <Protocol>Acme</Protocol>
            <Protocol>Sony</Protocol>
            <Protocol>Sharp</Protocol>
         </SyncProtocols>
      </Item>
   </Items>
</ItemLoad>    

Creating a Template

To create a template from an import file, copy the file without the XML declaration (the first line that indicates the XML version), and paste into the Sample field on the Import Manager Select Format step. Then, remove any duplicate elements. Since there is only a single Item element in the example above, it can be pasted as is.

Note: When creating a template from a source file, ensure all of the elements that can occur, and that must be handled, are represented. Only instructions included in both the document and the generic template are processed. Instructions not defined in the template are ignored.

Remove Redundant Elements

Click the Sample reload button and a message is displayed about sibling nodes with the same name:

Remove of repetitions of the 'Variants', 'Manual', and 'Protocol' elements, until only one of each remains. The Sample field now displays the following:

Copy
<ItemLoad>
   <Items>
      <Item>
         <EAN>2700524977488</EAN>
         <PrimarySpecs>
            <ProductInformation>
               <General>
                  <ProductName>AC-UZ444</ProductName>
                  <ConsumerShortDescription>Active 3D Glasses</ConsumerShortDescription>
                  <AvailableFrom>2015-01-01 00:00:00</AvailableFrom>
               </General>
               <Variants>
                  <Name>Color</Name>
                  <Value>Gray</Value>
               </Variants>
               <Manuals>
                  <Manual type="ManualDE">Manual-9</Manual>
               </Manuals>
            </ProductInformation>
         </PrimarySpecs>
         <SyncProtocols>
            <Protocol>Acme</Protocol>
         </SyncProtocols>
      </Item>
   </Items>
</ItemLoad>    

Add Record and Source Instructions

Click the Sample reload button and a message is displayed about a missing record declaration:

Use the <?Record?> and <?Source?> instructions to handle all the cases where you need to extract one value between a start and end tag.

Copy
<ItemLoad>
   <Items>
      <Item>
        <?Record?>
         <EAN><?Source?></EAN>
         <PrimarySpecs>
            <ProductInformation>
               <General>
                  <ProductName><?Source?></ProductName>
                  <ConsumerShortDescription><?Source?></ConsumerShortDescription>
                  <AvailableFrom><?Source?></AvailableFrom>
               </General>
               <Variants>
                  <Name>Color</Name>
                  <Value>Gray</Value>
               </Variants>
               <Manuals>
                  <Manual type="ManualDE">Manual-9</Manual>
               </Manuals>
            </ProductInformation>
         </PrimarySpecs>
         <SyncProtocols>
            <Protocol>Acme</Protocol>
         </SyncProtocols>
      </Item>
   </Items>
</ItemLoad>    

Add Repeated Instruction

To review how each option affects the outcome, make the following updates in the Sample template and then click the Sample reload button to update the Conversion Preview.

For the 'Variants' element, if we insert the <?Source?> instruction in the 'Value' element as shown below, the result will be the value for the first repetition, 'Gray.'

Copy
<Variants>
  <Name>Color</Name>
  <Value><?Source?></Value>
</Variants>    

To get values from both 'Variants' elements, we have two options: MultiSource and Source / Repeated / SourceID.

To get the Value from each repetition and be able to map them all to a multi valued attribute / multiple reference / links targets, we can use the <?MultiSource?> instruction.

Copy
<Variants>
    <Name>Color</Name>
    <Value><?MultiSource?></Value>
</Variants>    

If the data should be mapped to different attributes, as is the case in our example, where the Name value of each repetition identifies the attribute, use these three instructions:

  • <?Source?>
  • one <?Repeated?> to indicate that Variants is a repeated element
  • one <?SourceID?> to indicate that the Name value should be used as an identifier for each repetition
Copy
<Variants>
    <?Repeated?>
    <Name><?SourceID?></Name>
    <Value><?Source?></Value>
</Variants>    

The Import Manager displays the column header for each element using the pattern [Identifier].[SourceTagName].

Add Repeated Instruction With a Filter

To review how each option affects the outcome, make the following updates in the Sample template and then click the Sample reload button to update the Conversion Preview.

The repeated Manual element is handled differently since the type of identifier is an attribute.

Again, start by placing the <?Source?> instruction to the value:

Copy
<Manuals>
   <Manual type="ManualDE"><?Source?></Manual>
</Manuals>    

Again, to get values for all repetitions, use the <?Repeated?> instruction and also add an identifier instruction. This time, since the identifier is an attribute value, use the use the square bracket version [?SourceID?].

Copy
<Manuals>
    <Manual type="[?SourceID?]"><?Repeated?><?Source?></Manual>
</Manuals>    

To filter repeated elements so that only elements with specific identifiers are considered, add the identifier to the <?Repeated?> instruction. To get only ManualEN data, update the template as follows.

Copy
<Manuals>
    <Manual type="[?SourceID?]"><?Repeated ManualEN?><?Source?></Manual>
</Manuals>    

Add MultiSource Instruction

For the repeated Protocol element there is no identifier, so it makes sense to use the <?MultiSource?> processing instruction. When this instruction is used, the <?Repeated?> instruction is not required.

Copy
<SyncProtocols>
    <Protocol><?MultiSource?></Protocol>
</SyncProtocols>    

Now that all instructions have been added, the template is below.

Copy
<ItemLoad>
   <Items>
      <Item>
         <?Record?>
         <EAN><?Source?></EAN>
         <PrimarySpecs>
            <ProductInformation>
               <General>
                  <ProductName><?Source?></ProductName>
                  <ConsumerShortDescription><?Source?></ConsumerShortDescription>
                  <AvailableFrom><?Source?></AvailableFrom>
               </General>
               <Variants>
                  <?Repeated?>
                  <Name><?SourceID?></Name>
                  <Value><?Source?></Value>
               </Variants>
               <Manuals>
                  <Manual type="[?SourceID?]"><?Repeated?><?Source?></Manual>
               </Manuals>
            </ProductInformation>
         </PrimarySpecs>
         <SyncProtocols>
            <Protocol><?MultiSource?></Protocol>
         </SyncProtocols>
      </Item>
   </Items>
</ItemLoad>    

Conversion Preview

Click the Sample reload button . The Conversion Preview area displays the results of the input document against the provided template.