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="http://www.w3.org/2001/XMLSchema" xmlns:ns1="www.i.com/Data" targetNamespace="www.i.com/U_Data" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="Emp_Details" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="Employeeid" type="xs:short"/>
<xs:element name="Name">
<xs:complexType>
<xs:sequence>
<xs:element name="Firstname" type="xs:string"/>
<xs:element name="Lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Dependents" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="address" minOccurs="0">
<xs:complexType>
<xs:sequence>
<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:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="EmpAttribute" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Create the hierarchical schema in Informatica Cloud. The following image shows a sample hierarchical schema:
The structure definition details show the properties of the NodeLog structure definition, such as the description, structure definition model, user name, time of creation of the structure definition, and the list of output fields in the structure definition.
The following example shows the input file data that you want to use:
<w3s:root xmlns:w3s="http://www.w3schools.com">
<!--Zero or more repetitions:-->
<w3s:Emp_Details EmpAttribute="string">
<w3s:employee>
<w3s:Employeeid>1</w3s:Employeeid>
<w3s:Name>
<w3s:Firstname>Gina</w3s:Firstname>
<w3s:Lastname>Aniston</w3s:Lastname>
</w3s:Name>
<!--1 or more repetitions:-->
<w3s:Dependents>anyType</w3s:Dependents>
</w3s:employee>
<!--Optional:-->
<w3s:address>
<w3s:Addressid>2</w3s:Addressid>
<w3s:Employeeid>1</w3s:Employeeid>
<w3s:Line1>Long Tech Park</w3s:Line1>
<w3s:Line2>Industrial Zone</w3s:Line2>
<w3s:City>Wichita</w3s:City>
<w3s:State>KA</w3s:State>
<w3s:Zipcode>773301</w3s:Zipcode>
<w3s:Fromdate>2011-09-29</w3s:Fromdate>
</w3s:address>
</w3s:Emp_Details>
</w3s:root>
To parse the input file, use an 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 file 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 specify the name as NewXMLtoRelational. Configure it to use the hierarchical schema that you configured.
You connect the source object to the NewXMLtoRelational transformation. To map the incoming data to the fields of the transformation, select the NewXMLtoRelational transformation. In the Input Field Selection tab, map FIELD2 to the NewXMLtoRelational hierarchical schema input fields.
The following image shows the input field selection:
The Field Mapping tab shows the incoming fields that you can map to the Structure Parser input fields.
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:
EmpAttribute
Employeeid
Firstname
Lastname
Addressid
Employeeid1
Line1
Line2
string
1
Gina
Aniston
2
1
Long Tech Park
Industrial Zone
City
State
Zipcode
Fromdate
Wichita
KA
773301
9/29/2008 12:00:00 AM