Transformations > Hierarchy Parser transformation > Hierarchy Parser transformation example

Hierarchy Parser transformation example

You want to convert hierarchical data to relational data and write the data to a target file in a relational format.
You need to configure a hierarchical schema that uses a schema file to define the hierarchy of the input data.
The following example shows the schema hierarchy that you want to use:
<xs:schema xmlns:xs="" xmlns="" targetNamespace="" elementFormDefault="qualified">
<xs:element name="root">
<xs:element name="Emp_Details" minOccurs="0" maxOccurs="unbounded">
<xs:element name="employee">
<xs:element name="Employeeid" type="xs:short"/>
<xs:element name="Name">
<xs:element name="Firstname" type="xs:string"/>
<xs:element name="Lastname" type="xs:string"/>
<xs:element name="Dependents" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="address" minOccurs="0">
<xs:element name="Addressid" type="xs:byte"/>
<xs:element name="Employeeid" type="xs:short"/>
<xs:element name="Line1" type="xs:string"/>
<xs:element name="Line2" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="State" type="xs:string"/>
<xs:element name="Zipcode" type="xs:int"/>
<xs:element name="Fromdate" type="xs:date"/>
<xs:attribute name="EmpAttribute" type="xs:string"/>
The following example shows the input file data that you want to use:
<itm:root xmlns:itm="">
<!--Zero or more repetitions:-->
<itm:Emp_Details EmpAttribute="string">
<!--1 or more repetitions:-->
<itm:Line1>Long Tech Park</itm:Line1>
<itm:Line2>Industrial Zone</itm:Line2>
Create the hierarchical schema in Data Integration with the schema hierarchy that you want to use.
To parse the input data, use a Hierarchy Parser transformation in a mapping to transform the data from the hierarchical input. In the Mapping Designer, you add a source object that is flat file that contains the path to the data that you want to parse.
The following image shows the selected Source transformation:
The source object details show the the connection, type of source, and the input file.
You add an Hierarchy Parser transformation and use the name NewHierarchyParser. Configure it to use the hierarchical schema that you created.
You connect the source object to the NewHierarchyParser transformation. To map the incoming data to the fields of the transformation, select the NewHierarchyParser transformation. In the Input Field Selection tab, map the selected incoming field from the source transformation to the NewHierarchyParser hierarchical schema input field.
To map the data to relational fields, in the Field Mapping tab, select which schema elements are reflected as relational fields to the output.
The following image shows the field mapping selection:
The Field Mapping tab shows the incoming fields that you can map to the Structure Parser input fields.
Add a file target object for the fields.
The following image shows the mapping:
The mapping shows the data flow from the SourceLogFile source to a Structure Parser transformation with name LogParser. The Structure Parser transformations is linked to the TargetFile target.
Run the mapping to write the data in a relational format to the Target transformation.
The following example shows the relational output:
Long Tech Park
Industrial Zone
9/29/2008 12:00:00 AM